History

iv8: assemble packets to return complete frames

Janne Grunau committed 15 years ago

Commit cf543c61 parent c4b97fb1 file · +47 −24Browse files

Unified · Split

libavformat/iv8.c+47−24
@@ -55,33 +55,56 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap) · 54 unmodified lines
5555
5656 static int read_packet(AVFormatContext *s, AVPacket *pkt)
5757 {
58− int ret, size, pts, type;
59−retry:
60− type= avio_rb16(s->pb); // 257 or 258
61− size= avio_rb16(s->pb);
62−
63− avio_rb16(s->pb); //some flags, 0x80 indicates end of frame
64− avio_rb16(s->pb); //packet number
65− pts=avio_rb32(s->pb);
66− avio_rb32(s->pb); //6A 13 E3 88
67−
68− size -= 12;
69− if(size<1)
70− return -1;
71−
72− if(type==258){
73− avio_skip(s->pb, size);
74− goto retry;
58+ int ret, size, pts, type, flags;
59+ int first_pkt = 0;
60+ int frame_complete = 0;
61+
62+ while (!frame_complete) {
63+
64+ type = avio_rb16(s->pb); // 257 or 258
65+ size = avio_rb16(s->pb);
66+ flags = avio_rb16(s->pb); //some flags, 0x80 indicates end of frame
67+ avio_rb16(s->pb); //packet number
68+ pts = avio_rb32(s->pb);
69+ avio_rb32(s->pb); //6A 13 E3 88
70+
71+ frame_complete = flags & 0x80;
72+
73+ size -= 12;
74+ if (size < 1)
75+ return -1;
76+
77+ if (type == 258) {
78+ avio_skip(s->pb, size);
79+ frame_complete = 0;
80+ continue;
81+ }
82+
83+ if (!first_pkt) {
84+ ret = av_get_packet(s->pb, pkt, size);
85+ if (ret < 0)
86+ return ret;
87+ first_pkt = 1;
88+ pkt->pts = pts;
89+ pkt->pos -= 16;
90+ } else {
91+ ret = av_append_packet(s->pb, pkt, size);
92+ if (ret < 0) {
93+ av_log(s, AV_LOG_ERROR, "failed to grow packet\n");
94+ av_free_packet(pkt);
95+ return ret;
96+ }
97+ }
98+ if (ret < size) {
99+ av_log(s, AV_LOG_ERROR, "Truncated packet! Read %d of %d bytes\n",
100+ ret, size);
101+ pkt->flags |= AV_PKT_FLAG_CORRUPT;
102+ break;
103+ }
75104 }
76−
77− ret= av_get_packet(s->pb, pkt, size);
78−
79− pkt->pts= pts;
80− pkt->pos-=16;
81−
82105 pkt->stream_index = 0;
83106
84− return ret;
107+ return 0;
85108 }
86109
87110 AVInputFormat ff_iv8_demuxer = {

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