MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / pdv_read_header

Function pdv_read_header

libavformat/pdvdec.c:43–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43static int pdv_read_header(AVFormatContext *s)
44{
45 PDVDemuxContext *p = s->priv_data;
46 AVIOContext *pb = s->pb;
47 AVCodecParameters *par;
48 AVStream *st;
49 uint64_t start;
50 uint32_t fps;
51
52 avio_skip(pb, 16);
53
54 st = avformat_new_stream(s, NULL);
55 if (!st)
56 return AVERROR(ENOMEM);
57
58 par = st->codecpar;
59 par->codec_type = AVMEDIA_TYPE_VIDEO;
60 par->codec_id = AV_CODEC_ID_PDV;
61 st->start_time = 0;
62 st->duration =
63 st->nb_frames = avio_rl16(pb);
64 avio_skip(pb, 2);
65 fps = avio_rl32(pb);
66 st->avg_frame_rate = av_d2q(av_int2float(fps), INT_MAX);
67 par->width = avio_rl16(pb);
68 par->height = avio_rl16(pb);
69
70 avpriv_set_pts_info(st, 64, st->avg_frame_rate.den, st->avg_frame_rate.num);
71
72 p->current_frame = 0;
73 p->frame_flags = av_calloc(st->nb_frames + 1, sizeof(*p->frame_flags));
74 p->frame_offsets = av_calloc(st->nb_frames + 1, sizeof(*p->frame_offsets));
75
76 if (!p->frame_flags || !p->frame_offsets)
77 return AVERROR(ENOMEM);
78
79 for (int n = 0; n <= st->nb_frames; n++) {
80 const uint32_t entry = avio_rl32(pb);
81
82 p->frame_flags[n] = entry & 3;
83 p->frame_offsets[n] = entry >> 2;
84 }
85
86 start = avio_tell(pb);
87
88 for (int n = 0; n < st->nb_frames; n++) {
89 const uint64_t pos = start + p->frame_offsets[n];
90 const int32_t size = p->frame_offsets[n+1] - p->frame_offsets[n];
91 const int flags = p->frame_flags[n] & 1 ? AVINDEX_KEYFRAME : 0;
92
93 if (p->frame_flags[n] == 0 || size <= 0 ||
94 ((pb->seekable & AVIO_SEEKABLE_NORMAL) && pos + size > avio_size(pb)))
95 break;
96 av_add_index_entry(st, pos, n, size, 0, flags);
97 }
98
99 return 0;
100}

Callers

nothing calls this directly

Calls 11

avio_skipFunction · 0.85
avformat_new_streamFunction · 0.85
avio_rl16Function · 0.85
avio_rl32Function · 0.85
av_d2qFunction · 0.85
av_int2floatFunction · 0.85
avpriv_set_pts_infoFunction · 0.85
av_callocFunction · 0.85
avio_tellFunction · 0.85
avio_sizeFunction · 0.85
av_add_index_entryFunction · 0.85

Tested by

no test coverage detected