History

Allow the ASF header to be transferred split over multiple packets, as some servers happen to do. For this, we also move several header-size-related variables to the MMSTContext.

Patch by Zhentan Feng <spyfeng gmail com>. Originally committed as revision 24363 to svn://svn.ffmpeg.org/ffmpeg/trunk

Zhentan Feng committed 16 years ago

Commit e4a28be1 parent d6cc1121 file · +13 −12Browse files

Unified · Split

libavformat/mmst.c+13−12
@@ -120,6 +120,7 @@ typedef struct { · 119 unmodified lines
120 int asf_header_size; ///< Size of stored ASF header.120 int asf_header_size; ///< Size of stored ASF header.
121 int header_parsed; ///< The header has been received and parsed.121 int header_parsed; ///< The header has been received and parsed.
122 int asf_packet_len;122 int asf_packet_len;
123 int asf_header_read_size;
123 /*@}*/124 /*@}*/
124 125
125 int stream_num; ///< stream numbers.126 int stream_num; ///< stream numbers.
@@ -302,8 +303,6 @@ static MMSSCPacketType get_tcp_server_response(MMSContext *mms) · 176 unmodified lines
302 int packet_id_type;303 int packet_id_type;
303 int tmp;304 int tmp;
304 305
305 assert(mms->remaining_in_len==0);
306
307 // note we cache the first 8 bytes,306 // note we cache the first 8 bytes,
308 // then fill up the buffer with the others307 // then fill up the buffer with the others
309 tmp = AV_RL16(mms->in_buffer + 6);308 tmp = AV_RL16(mms->in_buffer + 6);
@@ -344,6 +343,9 @@ static MMSSCPacketType get_tcp_server_response(MMSContext *mms) · 34 unmodified lines
344 mms->remaining_in_len);343 mms->remaining_in_len);
345 mms->asf_header_size += mms->remaining_in_len;344 mms->asf_header_size += mms->remaining_in_len;
346 }345 }
346 // 0x04 means asf header is sent in multiple packets.
347 if (mms->incoming_flags == 0x04)
348 continue;
347 } else if(packet_id_type == mms->packet_id) {349 } else if(packet_id_type == mms->packet_id) {
348 packet_type = SC_PKT_ASF_MEDIA;350 packet_type = SC_PKT_ASF_MEDIA;
349 } else {351 } else {
@@ -440,15 +442,14 @@ static int asf_header_parser(MMSContext *mms) · 90 unmodified lines
440{442{
441 uint8_t *p = mms->asf_header;443 uint8_t *p = mms->asf_header;
442 uint8_t *end;444 uint8_t *end;
443 int flags, stream_id, real_header_size;445 int flags, stream_id;
444 mms->stream_num = 0;446 mms->stream_num = 0;
445 447
446 if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||448 if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
447 memcmp(p, ff_asf_header, sizeof(ff_asf_guid)))449 memcmp(p, ff_asf_header, sizeof(ff_asf_guid)))
448 return -1;450 return -1;
449 451
450 real_header_size = AV_RL64(p + sizeof(ff_asf_guid));452 end = mms->asf_header + mms->asf_header_size;
451 end = mms->asf_header + real_header_size;
452 453
453 p += sizeof(ff_asf_guid) + 14;454 p += sizeof(ff_asf_guid) + 14;
454 while(end - p >= sizeof(ff_asf_guid) + 8) {455 while(end - p >= sizeof(ff_asf_guid) + 8) {
@@ -519,20 +520,20 @@ static int read_data(MMSContext *mms, uint8_t *buf, const int buf_size) · 64 unmodified lines
519/** Read at most one media packet (or a whole header). */520/** Read at most one media packet (or a whole header). */
520static int read_mms_packet(MMSContext *mms, uint8_t *buf, int buf_size)521static int read_mms_packet(MMSContext *mms, uint8_t *buf, int buf_size)
521{522{
522 int result = 0, read_header_size = 0;523 int result = 0;
523 int size_to_copy;524 int size_to_copy;
524 525
525 do {526 do {
526 if(read_header_size < mms->asf_header_size && !mms->is_playing) {527 if(mms->asf_header_read_size < mms->asf_header_size && !mms->is_playing) {
527 /* Read from ASF header buffer */528 /* Read from ASF header buffer */
528 size_to_copy= FFMIN(buf_size,529 size_to_copy= FFMIN(buf_size,
529 mms->asf_header_size - read_header_size);530 mms->asf_header_size - mms->asf_header_read_size);
530 memcpy(buf, mms->asf_header + read_header_size, size_to_copy);531 memcpy(buf, mms->asf_header + mms->asf_header_read_size, size_to_copy);
531 read_header_size += size_to_copy;532 mms->asf_header_read_size += size_to_copy;
532 result += size_to_copy;533 result += size_to_copy;
533 dprintf(NULL, "Copied %d bytes from stored header. left: %d\n",534 dprintf(NULL, "Copied %d bytes from stored header. left: %d\n",
534 size_to_copy, mms->asf_header_size - read_header_size);535 size_to_copy, mms->asf_header_size - mms->asf_header_read_size);
535 if (mms->asf_header_size == read_header_size) {536 if (mms->asf_header_size == mms->asf_header_read_size) {
536 av_freep(&mms->asf_header);537 av_freep(&mms->asf_header);
537 mms->is_playing = 1;538 mms->is_playing = 1;
538 }539 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t