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

Function wsd_read_header

libavformat/wsddec.c:100–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100static int wsd_read_header(AVFormatContext *s)
101{
102 AVIOContext *pb = s->pb;
103 AVStream *st;
104 int version;
105 uint32_t text_offset, data_offset, channel_assign;
106 char playback_time[AV_TIMECODE_STR_SIZE];
107
108 st = avformat_new_stream(s, NULL);
109 if (!st)
110 return AVERROR(ENOMEM);
111
112 avio_skip(pb, 8);
113 version = avio_r8(pb);
114 av_log(s, AV_LOG_DEBUG, "version: %i.%i\n", version >> 4, version & 0xF);
115 avio_skip(pb, 11);
116
117 if (version < 0x10) {
118 text_offset = 0x80;
119 data_offset = 0x800;
120 avio_skip(pb, 8);
121 } else {
122 text_offset = avio_rb32(pb);
123 data_offset = avio_rb32(pb);
124 }
125
126 avio_skip(pb, 4);
127 av_timecode_make_smpte_tc_string2(playback_time, (AVRational){1,1}, avio_rb32(pb) & 0x00ffffffU, 1, 1);
128 av_dict_set(&s->metadata, "playback_time", playback_time, 0);
129
130 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
131 st->codecpar->codec_id = AV_CODEC_ID_DSD_MSBF;
132 st->codecpar->sample_rate = avio_rb32(pb) / 8;
133 avio_skip(pb, 4);
134 st->codecpar->ch_layout.nb_channels = avio_r8(pb) & 0xF;
135 st->codecpar->bit_rate = (int64_t)st->codecpar->ch_layout.nb_channels *
136 st->codecpar->sample_rate * 8LL;
137 if (!st->codecpar->ch_layout.nb_channels)
138 return AVERROR_INVALIDDATA;
139
140 avio_skip(pb, 3);
141 channel_assign = avio_rb32(pb);
142 if (!(channel_assign & 1)) {
143 uint64_t ch_mask = 0;
144 int i;
145 for (i = 1; i < 32; i++)
146 if ((channel_assign >> i) & 1)
147 ch_mask |= wsd_to_av_channel_layoyt(s, i);
148 av_channel_layout_from_mask(&st->codecpar->ch_layout, ch_mask);
149 }
150
151 avio_skip(pb, 16);
152 if (avio_rb32(pb))
153 avpriv_request_sample(s, "emphasis");
154
155 if (avio_seek(pb, text_offset, SEEK_SET) >= 0) {
156 get_metadata(s, "title", 128);
157 get_metadata(s, "composer", 128);

Callers

nothing calls this directly

Calls 12

avformat_new_streamFunction · 0.85
avio_skipFunction · 0.85
avio_r8Function · 0.85
av_logFunction · 0.85
avio_rb32Function · 0.85
av_dict_setFunction · 0.85
wsd_to_av_channel_layoytFunction · 0.85
avpriv_request_sampleFunction · 0.85
avio_seekFunction · 0.85
get_metadataFunction · 0.70

Tested by

no test coverage detected