UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
rtpdec_jpeg.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int decode_frame_jpeg (struct coded_data *cdata, void *decode_data)
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file rtpdec_jpeg.h.

Function Documentation

◆ decode_frame_jpeg()

int decode_frame_jpeg ( struct coded_data * cdata,
void * decode_data )

Definition at line 267 of file rtpdec_jpeg.c.

268{
269 struct decode_data_rtsp *dec_data = decode_data;
270
271 struct video_frame *frame = dec_data->frame;
272 // table with Q=255 must be always (re)set
274 uint8_t q = -1;
275 unsigned received_bytes = 0;
276 unsigned frame_max_len = 0; // off + data_len
277
278 while (cdata != NULL) {
279 rtp_packet *pckt = cdata->data;
280 unsigned char *pckt_data = (unsigned char *) pckt->data;
281
282 uint32_t hdr = 0;
283 memcpy(&hdr, pckt_data, sizeof hdr);
284 const unsigned off = ntohl(hdr) & 0xFFFFFFU;
285 memcpy(&q, pckt_data + 5, sizeof q);
286 if (frame->tiles[0].width == 0) {
287 char *hdr_end = create_jpeg_frame(
288 frame, &pckt_data, &dec_data->jpeg.dqt_start,
289 dec_data->jpeg.not_first_run);
290 if (hdr_end == NULL) {
291 return false;
292 }
293 dec_data->offset_len =
294 (int) (hdr_end - frame->tiles[0].data);
295 } else {
296 skip_jpeg_headers(&pckt_data);
297 }
298 // for q>=128, 1st pckt contains tables
299 if (off == 0 && q >= QUANT_TAB_T_FIRST_STATIC) {
300 const unsigned char *end =
301 (unsigned char *) pckt->data + pckt->data_len;
302 parse_quant_tables(dec_data, &pckt_data, end, q);
303 }
304
305 const long payload_hdr_len =
306 pckt_data - (unsigned char *) pckt->data;
307 const long data_len = pckt->data_len - payload_hdr_len;
308 const unsigned frame_off = off + dec_data->offset_len;
309 memcpy(frame->tiles[0].data + frame_off, pckt_data, data_len);
310
311 received_bytes += data_len;
312 frame_max_len = MAX(frame_max_len, off + data_len);
313
314 cdata = cdata->nxt;
315 }
316
317 if (!dec_data->jpeg.quantization_table_set[q] &&
319 MakeTables(q, dec_data->jpeg.quantization_tables[q][0],
320 dec_data->jpeg.quantization_tables[q][1]);
321 dec_data->jpeg.quantization_table_set[q] = true;
322 }
323
324 if (!dec_data->jpeg.quantization_table_set[q]) {
325 MSG(WARNING,
326 "Dropping frame - missing quantization tables for Q=%d!\n",
327 q);
328 return false;
329 }
330
332 dec_data->jpeg.quantization_tables[q]);
333
334 char *frame_end =
335 frame->tiles[0].data + dec_data->offset_len + frame_max_len;
336 jpeg_writer_write_eoi(&frame_end);
337 frame->tiles[0].data_len = frame_end - frame->tiles[0].data;
338
339 if (received_bytes != frame_max_len) {
340 MSG(DEBUG, "Frame incomplete - expected %u bytes, got %u B!\n",
341 frame_max_len, received_bytes);
342 }
343
344 dec_data->jpeg.not_first_run = 1;
345
346 return true;
347}
struct video_frame * frame
#define MSG(l, fmt,...)
Definition debug.h:96
void jpeg_writer_fill_dqt(char *buffer, uint8_t quant_table[2][JPEG_QUANT_SIZE])
void jpeg_writer_write_eoi(char **buffer)
#define MAX(a, b)
Definition macros.h:65
#define DEBUG
Definition main.c:27
rtp_packet
Definition rtp.h:126
@ QUANT_TAB_T_DYN
Q=255.
Definition rtpdec_jpeg.c:67
@ QUANT_TAB_T_FIRST_STATIC
Definition rtpdec_jpeg.c:66
static char * create_jpeg_frame(struct video_frame *frame, unsigned char **pckt_data, char **dqt_start, int verbose_adj)
static void MakeTables(int q, u_char *lqt, u_char *cqt)
static void skip_jpeg_headers(unsigned char **pckt_data)
static void parse_quant_tables(struct decode_data_rtsp *dec, unsigned char **pckt_data, const unsigned char *end, int q)
Definition rtpdec_jpeg.c:89
rtp_packet * data
Definition pbuf.h:75
struct coded_data * nxt
Definition pbuf.h:72
struct decode_data_rtsp::@46::@49 jpeg
int not_first_run
decrease verbosity next time
bool quantization_table_set[JPEG_QUANT_TAB_COUNT]
struct video_frame * frame
uint8_t quantization_tables[JPEG_QUANT_TAB_COUNT][JPEG_Q_TAB_COUNT][JPEG_QUANT_SIZE]
unsigned int width
Definition types.h:280
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
unsigned int data_len
length of the data
Definition types.h:288
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345

References create_jpeg_frame(), coded_data::data, tile::data, tile::data_len, DEBUG, decode_data_rtsp::dqt_start, decode_data_rtsp::frame, frame, decode_data_rtsp::jpeg, jpeg_writer_fill_dqt(), jpeg_writer_write_eoi(), MakeTables(), MAX, MSG, decode_data_rtsp::not_first_run, coded_data::nxt, decode_data_rtsp::offset_len, parse_quant_tables(), QUANT_TAB_T_DYN, QUANT_TAB_T_FIRST_STATIC, decode_data_rtsp::quantization_table_set, decode_data_rtsp::quantization_tables, rtp_packet, skip_jpeg_headers(), video_frame::tiles, and tile::width.

Referenced by init_rtsp().

Here is the call graph for this function: