FFmpeg  4.3
brstm.c
Go to the documentation of this file.
1 /*
2  * BRSTM demuxer
3  * Copyright (c) 2012 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/intreadwrite.h"
23 #include "libavcodec/bytestream.h"
24 #include "avformat.h"
25 #include "internal.h"
26 
27 typedef struct BRSTMDemuxContext {
28  uint32_t block_size;
29  uint32_t block_count;
30  uint32_t current_block;
33  uint32_t last_block_size;
35  uint32_t data_start;
40 
41 static int probe(const AVProbeData *p)
42 {
43  if (AV_RL32(p->buf) == MKTAG('R','S','T','M') &&
44  (AV_RL16(p->buf + 4) == 0xFFFE ||
45  AV_RL16(p->buf + 4) == 0xFEFF))
46  return AVPROBE_SCORE_MAX / 3 * 2;
47  return 0;
48 }
49 
50 static int probe_bfstm(const AVProbeData *p)
51 {
52  if ((AV_RL32(p->buf) == MKTAG('F','S','T','M') ||
53  AV_RL32(p->buf) == MKTAG('C','S','T','M')) &&
54  (AV_RL16(p->buf + 4) == 0xFFFE ||
55  AV_RL16(p->buf + 4) == 0xFEFF))
56  return AVPROBE_SCORE_MAX / 3 * 2;
57  return 0;
58 }
59 
61 {
62  BRSTMDemuxContext *b = s->priv_data;
63 
64  av_freep(&b->table);
65  av_freep(&b->adpc);
66 
67  return 0;
68 }
69 
71 {
72  BRSTMDemuxContext *b = s->priv_data;
73  if (b->little_endian)
74  return avio_rl16(s->pb);
75  else
76  return avio_rb16(s->pb);
77 }
78 
80 {
81  BRSTMDemuxContext *b = s->priv_data;
82  if (b->little_endian)
83  return avio_rl32(s->pb);
84  else
85  return avio_rb32(s->pb);
86 }
87 
89 {
90  BRSTMDemuxContext *b = s->priv_data;
91  int bom, major, minor, codec, chunk;
92  int64_t h1offset, pos, toffset;
93  uint32_t size, asize, start = 0;
94  AVStream *st;
95  int ret = AVERROR_EOF;
96  int loop = 0;
97  int bfstm = !strcmp("bfstm", s->iformat->name);
98 
99  st = avformat_new_stream(s, NULL);
100  if (!st)
101  return AVERROR(ENOMEM);
103 
104  avio_skip(s->pb, 4);
105 
106  bom = avio_rb16(s->pb);
107  if (bom != 0xFEFF && bom != 0xFFFE) {
108  av_log(s, AV_LOG_ERROR, "invalid byte order: %X\n", bom);
109  return AVERROR_INVALIDDATA;
110  }
111 
112  if (bom == 0xFFFE)
113  b->little_endian = 1;
114 
115  if (!bfstm) {
116  major = avio_r8(s->pb);
117  minor = avio_r8(s->pb);
118  avio_skip(s->pb, 4); // size of file
119  size = read16(s);
120  if (size < 14)
121  return AVERROR_INVALIDDATA;
122 
123  avio_skip(s->pb, size - 14);
124  pos = avio_tell(s->pb);
125  if (avio_rl32(s->pb) != MKTAG('H','E','A','D'))
126  return AVERROR_INVALIDDATA;
127  } else {
128  uint32_t info_offset = 0;
129  uint16_t section_count, header_size, i;
130 
131  header_size = read16(s); // 6
132 
133  avio_skip(s->pb, 4); // Unknown constant 0x00030000
134  avio_skip(s->pb, 4); // size of file
135  section_count = read16(s);
136  avio_skip(s->pb, 2); // padding
137  for (i = 0; avio_tell(s->pb) < header_size
138  && !(start && info_offset)
139  && i < section_count; i++) {
140  uint16_t flag = read16(s);
141  avio_skip(s->pb, 2);
142  switch (flag) {
143  case 0x4000:
144  info_offset = read32(s);
145  /*info_size =*/ read32(s);
146  break;
147  case 0x4001:
148  avio_skip(s->pb, 4); // seek offset
149  avio_skip(s->pb, 4); // seek size
150  break;
151  case 0x4002:
152  start = read32(s) + 8;
153  avio_skip(s->pb, 4); //data_size = read32(s);
154  break;
155  case 0x4003:
156  avio_skip(s->pb, 4); // REGN offset
157  avio_skip(s->pb, 4); // REGN size
158  break;
159  }
160  }
161 
162  if (!info_offset || !start)
163  return AVERROR_INVALIDDATA;
164 
165  avio_skip(s->pb, info_offset - avio_tell(s->pb));
166  pos = avio_tell(s->pb);
167  if (avio_rl32(s->pb) != MKTAG('I','N','F','O'))
168  return AVERROR_INVALIDDATA;
169  }
170 
171  size = read32(s);
172  if (size < 40)
173  return AVERROR_INVALIDDATA;
174  avio_skip(s->pb, 4); // unknown
175  h1offset = read32(s);
176  if (h1offset > size)
177  return AVERROR_INVALIDDATA;
178  avio_skip(s->pb, 12);
179  toffset = read32(s) + 16LL;
180  if (toffset > size)
181  return AVERROR_INVALIDDATA;
182 
183  avio_skip(s->pb, pos + h1offset + 8 - avio_tell(s->pb));
184  codec = avio_r8(s->pb);
185 
186  switch (codec) {
187  case 0: codec = AV_CODEC_ID_PCM_S8_PLANAR; break;
188  case 1: codec = b->little_endian ?
191  case 2: codec = b->little_endian ?
193  AV_CODEC_ID_ADPCM_THP; break;
194  default:
195  avpriv_request_sample(s, "codec %d", codec);
196  return AVERROR_PATCHWELCOME;
197  }
198 
199  loop = avio_r8(s->pb); // loop flag
200  st->codecpar->codec_id = codec;
201  st->codecpar->channels = avio_r8(s->pb);
202  if (!st->codecpar->channels)
203  return AVERROR_INVALIDDATA;
204 
205  avio_skip(s->pb, 1); // padding
206 
207  st->codecpar->sample_rate = bfstm ? read32(s) : read16(s);
208  if (st->codecpar->sample_rate <= 0)
209  return AVERROR_INVALIDDATA;
210 
211  if (!bfstm)
212  avio_skip(s->pb, 2); // padding
213 
214  if (loop) {
215  if (av_dict_set_int(&s->metadata, "loop_start",
217  st->codecpar->sample_rate),
218  0) < 0)
219  return AVERROR(ENOMEM);
220  } else {
221  avio_skip(s->pb, 4);
222  }
223 
224  st->start_time = 0;
225  st->duration = read32(s);
226  avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
227 
228  if (!bfstm)
229  start = read32(s);
230  b->current_block = 0;
231  b->block_count = read32(s);
232  if (b->block_count > UINT16_MAX) {
233  av_log(s, AV_LOG_WARNING, "too many blocks: %"PRIu32"\n", b->block_count);
234  return AVERROR_INVALIDDATA;
235  }
236 
237  b->block_size = read32(s);
238  if (b->block_size > UINT32_MAX / st->codecpar->channels)
239  return AVERROR_INVALIDDATA;
240 
241  b->samples_per_block = read32(s);
242  b->last_block_used_bytes = read32(s);
243  b->last_block_samples = read32(s);
244  b->last_block_size = read32(s);
245  if (b->last_block_size > UINT32_MAX / st->codecpar->channels)
246  return AVERROR_INVALIDDATA;
247  if (b->last_block_used_bytes > b->last_block_size)
248  return AVERROR_INVALIDDATA;
249 
250 
251  if (codec == AV_CODEC_ID_ADPCM_THP || codec == AV_CODEC_ID_ADPCM_THP_LE) {
252  int ch;
253 
254  avio_skip(s->pb, pos + toffset - avio_tell(s->pb));
255  if (!bfstm)
256  toffset = read32(s) + 16LL;
257  else
258  toffset = toffset + read32(s) + st->codecpar->channels * 8 - 8;
259  if (toffset > size)
260  return AVERROR_INVALIDDATA;
261 
262  avio_skip(s->pb, pos + toffset - avio_tell(s->pb));
263  b->table = av_mallocz(32 * st->codecpar->channels);
264  if (!b->table)
265  return AVERROR(ENOMEM);
266 
267  for (ch = 0; ch < st->codecpar->channels; ch++) {
268  if (avio_read(s->pb, b->table + ch * 32, 32) != 32) {
270  goto fail;
271  }
272  avio_skip(s->pb, bfstm ? 14 : 24);
273  }
274  }
275 
276  if (size < (avio_tell(s->pb) - pos)) {
278  goto fail;
279  }
280 
281  avio_skip(s->pb, size - (avio_tell(s->pb) - pos));
282 
283  while (!avio_feof(s->pb)) {
284  chunk = avio_rl32(s->pb);
285  size = read32(s);
286  if (size < 8) {
288  goto fail;
289  }
290  size -= 8;
291  switch (chunk) {
292  case MKTAG('S','E','E','K'):
293  case MKTAG('A','D','P','C'):
294  if (codec != AV_CODEC_ID_ADPCM_THP &&
295  codec != AV_CODEC_ID_ADPCM_THP_LE)
296  goto skip;
297 
298  asize = b->block_count * st->codecpar->channels * 4;
299  if (size < asize) {
301  goto fail;
302  }
303  if (b->adpc) {
304  av_log(s, AV_LOG_WARNING, "skipping additional ADPC chunk\n");
305  goto skip;
306  } else {
307  b->adpc = av_mallocz(asize);
308  if (!b->adpc) {
309  ret = AVERROR(ENOMEM);
310  goto fail;
311  }
312  if (bfstm && codec != AV_CODEC_ID_ADPCM_THP_LE) {
313  // Big-endian BFSTMs have little-endian SEEK tables
314  // for some strange reason.
315  int i;
316  for (i = 0; i < asize; i += 2) {
317  b->adpc[i+1] = avio_r8(s->pb);
318  b->adpc[i] = avio_r8(s->pb);
319  }
320  } else {
321  avio_read(s->pb, b->adpc, asize);
322  }
323  avio_skip(s->pb, size - asize);
324  }
325  break;
326  case MKTAG('D','A','T','A'):
327  if ((start < avio_tell(s->pb)) ||
328  (!b->adpc && (codec == AV_CODEC_ID_ADPCM_THP ||
329  codec == AV_CODEC_ID_ADPCM_THP_LE))) {
331  goto fail;
332  }
333  avio_skip(s->pb, start - avio_tell(s->pb));
334 
335  if (bfstm && (codec == AV_CODEC_ID_ADPCM_THP ||
336  codec == AV_CODEC_ID_ADPCM_THP_LE))
337  avio_skip(s->pb, 24);
338 
339  b->data_start = avio_tell(s->pb);
340 
341  if (!bfstm && (major != 1 || minor))
342  avpriv_request_sample(s, "Version %d.%d", major, minor);
343 
344  return 0;
345  default:
346  av_log(s, AV_LOG_WARNING, "skipping unknown chunk: %X\n", chunk);
347 skip:
348  avio_skip(s->pb, size);
349  }
350  }
351 
352 fail:
353  read_close(s);
354 
355  return ret;
356 }
357 
359 {
360  AVCodecParameters *par = s->streams[0]->codecpar;
361  BRSTMDemuxContext *b = s->priv_data;
362  uint32_t samples, size, skip = 0;
363  int ret, i;
364 
365  if (avio_feof(s->pb))
366  return AVERROR_EOF;
367  b->current_block++;
368  if (b->current_block == b->block_count) {
369  size = b->last_block_used_bytes;
370  samples = b->last_block_samples;
371  skip = b->last_block_size - b->last_block_used_bytes;
372 
373  if (samples < size * 14 / 8) {
374  uint32_t adjusted_size = samples / 14 * 8;
375  if (samples % 14)
376  adjusted_size += (samples % 14 + 1) / 2 + 1;
377 
378  skip += size - adjusted_size;
379  size = adjusted_size;
380  }
381  } else if (b->current_block < b->block_count) {
382  size = b->block_size;
383  samples = b->samples_per_block;
384  } else {
385  return AVERROR_EOF;
386  }
387 
388  if (par->codec_id == AV_CODEC_ID_ADPCM_THP ||
390  uint8_t *dst;
391 
392  if (!b->adpc) {
393  av_log(s, AV_LOG_ERROR, "adpcm_thp requires ADPC chunk, but none was found.\n");
394  return AVERROR_INVALIDDATA;
395  }
396  if (!b->table) {
397  b->table = av_mallocz(32 * par->channels);
398  if (!b->table)
399  return AVERROR(ENOMEM);
400  }
401 
402  if (size > (INT_MAX - 32 - 4) ||
403  (32 + 4 + size) > (INT_MAX / par->channels) ||
404  (32 + 4 + size) * par->channels > INT_MAX - 8)
405  return AVERROR_INVALIDDATA;
406  if ((ret = av_new_packet(pkt, 8 + (32 + 4 + size) * par->channels)) < 0)
407  return ret;
408  dst = pkt->data;
409  if (par->codec_id == AV_CODEC_ID_ADPCM_THP_LE) {
410  bytestream_put_le32(&dst, size * par->channels);
411  bytestream_put_le32(&dst, samples);
412  } else {
413  bytestream_put_be32(&dst, size * par->channels);
414  bytestream_put_be32(&dst, samples);
415  }
416  bytestream_put_buffer(&dst, b->table, 32 * par->channels);
417  bytestream_put_buffer(&dst, b->adpc + 4 * par->channels *
418  (b->current_block - 1), 4 * par->channels);
419 
420  for (i = 0; i < par->channels; i++) {
421  ret = avio_read(s->pb, dst, size);
422  dst += size;
423  avio_skip(s->pb, skip);
424  if (ret != size) {
425  return AVERROR(EIO);
426  }
427  }
428  pkt->duration = samples;
429  } else {
430  size *= par->channels;
431  ret = av_get_packet(s->pb, pkt, size);
432  }
433 
434  pkt->stream_index = 0;
435 
436  if (ret != size)
437  ret = AVERROR(EIO);
438 
439  return ret;
440 }
441 
442 static int read_seek(AVFormatContext *s, int stream_index,
443  int64_t timestamp, int flags)
444 {
445  AVStream *st = s->streams[stream_index];
446  BRSTMDemuxContext *b = s->priv_data;
447  int64_t ret = 0;
448 
449  timestamp /= b->samples_per_block;
450  ret = avio_seek(s->pb, b->data_start + timestamp * b->block_size *
451  st->codecpar->channels, SEEK_SET);
452  if (ret < 0)
453  return ret;
454 
455  b->current_block = timestamp;
456  ff_update_cur_dts(s, st, timestamp * b->samples_per_block);
457  return 0;
458 }
459 
461  .name = "brstm",
462  .long_name = NULL_IF_CONFIG_SMALL("BRSTM (Binary Revolution Stream)"),
463  .priv_data_size = sizeof(BRSTMDemuxContext),
464  .read_probe = probe,
468  .read_seek = read_seek,
469  .extensions = "brstm",
470 };
471 
473  .name = "bfstm",
474  .long_name = NULL_IF_CONFIG_SMALL("BFSTM (Binary Cafe Stream)"),
475  .priv_data_size = sizeof(BRSTMDemuxContext),
480  .read_seek = read_seek,
481  .extensions = "bfstm,bcstm",
482 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4519
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
read_seek
static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: brstm.c:442
BRSTMDemuxContext::last_block_used_bytes
uint32_t last_block_used_bytes
Definition: brstm.c:32
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
ff_brstm_demuxer
AVInputFormat ff_brstm_demuxer
Definition: brstm.c:460
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
MKTAG
#define MKTAG(a, b, c, d)
Definition: common.h:406
AVPacket::data
uint8_t * data
Definition: packet.h:355
AV_CODEC_ID_PCM_S16BE_PLANAR
@ AV_CODEC_ID_PCM_S16BE_PLANAR
Definition: codec_id.h:331
b
#define b
Definition: input.c:41
BRSTMDemuxContext::table
uint8_t * table
Definition: brstm.c:36
samples
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new samples
Definition: fate.txt:139
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:373
BRSTMDemuxContext::last_block_size
uint32_t last_block_size
Definition: brstm.c:33
BRSTMDemuxContext::last_block_samples
uint32_t last_block_samples
Definition: brstm.c:34
AV_CODEC_ID_PCM_S16LE_PLANAR
@ AV_CODEC_ID_PCM_S16LE_PLANAR
Definition: codec_id.h:319
AV_CODEC_ID_ADPCM_THP_LE
@ AV_CODEC_ID_ADPCM_THP_LE
Definition: codec_id.h:377
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:453
AVCodecParameters::channels
int channels
Audio only.
Definition: codec_par.h:166
fail
#define fail()
Definition: checkasm.h:123
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:914
loop
static int loop
Definition: ffplay.c:341
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:731
BRSTMDemuxContext::block_size
uint32_t block_size
Definition: brstm.c:28
BRSTMDemuxContext::current_block
uint32_t current_block
Definition: brstm.c:30
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:778
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVInputFormat
Definition: avformat.h:636
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:88
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:641
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
AV_RL16
#define AV_RL16
Definition: intreadwrite.h:42
read_close
static int read_close(AVFormatContext *s)
Definition: brstm.c:60
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
AVFormatContext
Format I/O context.
Definition: avformat.h:1335
internal.h
ff_update_cur_dts
void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
Update cur_dts of all streams based on the given timestamp and AVStream.
Definition: utils.c:1959
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1012
NULL
#define NULL
Definition: coverity.c:32
BRSTMDemuxContext::adpc
uint8_t * adpc
Definition: brstm.c:37
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
convert_header.major
int major
Definition: convert_header.py:23
BRSTMDemuxContext::samples_per_block
uint32_t samples_per_block
Definition: brstm.c:31
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:170
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:747
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:186
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4938
size
int size
Definition: twinvq_data.h:11134
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:616
flag
#define flag(name)
Definition: cbs_av1.c:556
convert_header.minor
int minor
Definition: convert_header.py:26
bytestream_put_buffer
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:368
BRSTMDemuxContext::block_count
uint32_t block_count
Definition: brstm.c:29
BRSTMDemuxContext
Definition: brstm.c:27
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
av_always_inline
#define av_always_inline
Definition: attributes.h:49
uint8_t
uint8_t
Definition: audio_convert.c:194
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
BRSTMDemuxContext::data_start
uint32_t data_start
Definition: brstm.c:35
ff_bfstm_demuxer
AVInputFormat ff_bfstm_demuxer
Definition: brstm.c:472
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:304
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:865
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:241
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:763
pos
unsigned int pos
Definition: spdifenc.c:410
avformat.h
read32
static av_always_inline unsigned int read32(AVFormatContext *s)
Definition: brstm.c:79
probe
static int probe(const AVProbeData *p)
Definition: brstm.c:41
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AV_RL32
#define AV_RL32
Definition: intreadwrite.h:146
probe_bfstm
static int probe_bfstm(const AVProbeData *p)
Definition: brstm.c:50
BRSTMDemuxContext::little_endian
int little_endian
Definition: brstm.c:38
read_packet
static int read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: brstm.c:358
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:625
AVPacket::stream_index
int stream_index
Definition: packet.h:357
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:329
av_dict_set_int
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set that converts the value to a string and stores it.
Definition: dict.c:147
AV_CODEC_ID_ADPCM_THP
@ AV_CODEC_ID_ADPCM_THP
Definition: codec_id.h:358
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:332
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_CODEC_ID_PCM_S8_PLANAR
@ AV_CODEC_ID_PCM_S8_PLANAR
Definition: codec_id.h:328
bytestream.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:564
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:904
read_header
static int read_header(AVFormatContext *s)
Definition: brstm.c:88
read16
static av_always_inline unsigned int read16(AVFormatContext *s)
Definition: brstm.c:70
bom
static const char * bom
Definition: microdvddec.c:77
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:356