comparison rdt.c @ 4053:06642e6ba288 libavformat

Implement rule-number parsing, the initial step in stream (and bitrate) selection. See discussion in ML thread "[PATCH] RDT/Realmedia patches #2".
author rbultje
date Mon, 01 Dec 2008 00:08:42 +0000
parents 302cc68489e4
children 8adccfc01be3
comparison
equal deleted inserted replaced
4052:302cc68489e4 4053:06642e6ba288
45 AVStream **streams; 45 AVStream **streams;
46 int n_streams; /**< streams with identifical content in this set */ 46 int n_streams; /**< streams with identifical content in this set */
47 void *dynamic_protocol_context; 47 void *dynamic_protocol_context;
48 DynamicPayloadPacketHandlerProc parse_packet; 48 DynamicPayloadPacketHandlerProc parse_packet;
49 uint32_t prev_timestamp; 49 uint32_t prev_timestamp;
50 int prev_set_id; 50 int prev_set_id, prev_stream_id;
51 }; 51 };
52 52
53 RDTDemuxContext * 53 RDTDemuxContext *
54 ff_rdt_parse_open(AVFormatContext *ic, int first_stream_of_set_idx, 54 ff_rdt_parse_open(AVFormatContext *ic, int first_stream_of_set_idx,
55 void *priv_data, RTPDynamicProtocolHandler *handler) 55 void *priv_data, RTPDynamicProtocolHandler *handler)
63 do { 63 do {
64 s->n_streams++; 64 s->n_streams++;
65 } while (first_stream_of_set_idx + s->n_streams < ic->nb_streams && 65 } while (first_stream_of_set_idx + s->n_streams < ic->nb_streams &&
66 s->streams[s->n_streams]->priv_data == s->streams[0]->priv_data); 66 s->streams[s->n_streams]->priv_data == s->streams[0]->priv_data);
67 s->prev_set_id = -1; 67 s->prev_set_id = -1;
68 s->prev_stream_id = -1;
68 s->prev_timestamp = -1; 69 s->prev_timestamp = -1;
69 s->parse_packet = handler->parse_packet; 70 s->parse_packet = handler->parse_packet;
70 s->dynamic_protocol_context = priv_data; 71 s->dynamic_protocol_context = priv_data;
71 72
72 return s; 73 return s;
332 int rv= 0; 333 int rv= 0;
333 334
334 if (!s->parse_packet) 335 if (!s->parse_packet)
335 return -1; 336 return -1;
336 337
337 if (!buf) { 338 if (!buf && s->prev_stream_id != -1) {
338 /* return the next packets, if any */ 339 /* return the next packets, if any */
339 timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned.... 340 timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned....
340 rv= s->parse_packet(s->dynamic_protocol_context, 341 rv= s->parse_packet(s->dynamic_protocol_context,
341 s->streams[0], pkt, &timestamp, NULL, 0, flags); 342 s->streams[s->prev_stream_id],
343 pkt, &timestamp, NULL, 0, flags);
342 return rv; 344 return rv;
343 } 345 }
344 346
345 if (len < 12) 347 if (len < 12)
346 return -1; 348 return -1;
347 rv = ff_rdt_parse_header(buf, len, &set_id, &seq_no, &stream_id, &is_keyframe, &timestamp); 349 rv = ff_rdt_parse_header(buf, len, &set_id, &seq_no, &stream_id, &is_keyframe, &timestamp);
348 if (rv < 0) 350 if (rv < 0)
349 return rv; 351 return rv;
350 if (is_keyframe && (set_id != s->prev_set_id || timestamp != s->prev_timestamp)) { 352 if (is_keyframe &&
353 (set_id != s->prev_set_id || timestamp != s->prev_timestamp ||
354 stream_id != s->prev_stream_id)) {
351 flags |= PKT_FLAG_KEY; 355 flags |= PKT_FLAG_KEY;
352 s->prev_set_id = set_id; 356 s->prev_set_id = set_id;
353 s->prev_timestamp = timestamp; 357 s->prev_timestamp = timestamp;
354 } 358 }
359 s->prev_stream_id = stream_id;
355 buf += rv; 360 buf += rv;
356 len -= rv; 361 len -= rv;
357 362
363 if (s->prev_stream_id >= s->n_streams) {
364 s->prev_stream_id = -1;
365 return -1;
366 }
367
358 rv = s->parse_packet(s->dynamic_protocol_context, 368 rv = s->parse_packet(s->dynamic_protocol_context,
359 s->streams[0], pkt, &timestamp, buf, len, flags); 369 s->streams[s->prev_stream_id],
370 pkt, &timestamp, buf, len, flags);
360 371
361 return rv; 372 return rv;
362 } 373 }
363 374
364 void 375 void