36 #include "libavutil/channel_layout.h"
37 #include "libavutil/intreadwrite.h"
38 #include "libavutil/mathematics.h"
39 #include "libavutil/timecode.h"
41 #include "libavutil/avassert.h"
57 uint16_t
shift, result;
59 sample = (sample < 0x800) ? sample : sample | 0xf000;
60 shift = (sample & 0xf00) >> 8;
62 if (shift < 0x2 || shift > 0xd) {
64 }
else if (shift < 0x8) {
69 result = ((sample + ((256 *
shift) + 1)) << shift) - 1;
86 offs = (80 * 6 + 80 * 16 * 3 + 3);
89 offs = (80 * 6 + 80 * 16 * 4 + 3);
92 offs = (80 * 5 + 48 + 5);
95 offs = (80*1 + 3 + 3);
101 return frame[offs] == t ? &frame[offs] : NULL;
119 int size, chan, i, j, d, of, smpls, freq,
quant, half_ch;
128 smpls = as_pack[1] & 0x3f;
129 freq = as_pack[4] >> 3 & 0x07;
130 quant = as_pack[4] & 0x07;
143 ipcm = (sys->
height == 720 && !(frame[1] & 0x0C)) ? 2 : 0;
145 if (ipcm + sys->
n_difchan > (quant == 1 ? 2 : 4)) {
151 for (chan = 0; chan < sys->
n_difchan; chan++) {
160 if (quant == 1 && i == half_ch) {
169 for (j = 0; j < 9; j++) {
170 for (d = 8; d < 80; d += 2) {
179 pcm[of * 2] = frame[d + 1];
180 pcm[of * 2 + 1] = frame[d];
182 if (pcm[of * 2 + 1] == 0x80 && pcm[of * 2] == 0x00)
185 lc = ((uint16_t)frame[d] << 4) |
186 ((uint16_t)frame[d + 2] >> 4);
187 rc = ((uint16_t)frame[d + 1] << 4) |
188 ((uint16_t)frame[d + 2] & 0x0f);
199 pcm[of * 2] = lc & 0xff;
200 pcm[of * 2 + 1] = lc >> 8;
205 pcm[of * 2] = rc & 0xff;
206 pcm[of * 2 + 1] = rc >> 8;
222 int freq, stype, smpls,
quant, i, ach;
225 if (!as_pack || !c->
sys) {
230 smpls = as_pack[1] & 0x3f;
231 freq = as_pack[4] >> 3 & 0x07;
232 stype = as_pack[3] & 0x1f;
233 quant = as_pack[4] & 0x07;
237 "Unrecognized audio sample rate index (%d)\n", freq);
248 ach = ((
int[4]) { 1, 0, 2, 4 })[stype];
249 if (ach == 1 && quant && freq == 2)
253 for (i = 0; i < ach; i++) {
295 apt = frame[4] & 0x07;
296 is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
297 (!apt && (vsc_pack[2] & 0x07) == 0x07)));
353 for (i = 0; i < c->
ach; i++) {
373 buf_size < c->sys->frame_size) {
380 for (i = 0; i < c->
ach; i++) {
419 int64_t timestamp,
int flags)
429 if (size >= 0 && offset > max_offset)
447 c->audio_pkt[0].size =
c->audio_pkt[1].size = 0;
448 c->audio_pkt[2].size =
c->audio_pkt[3].size = 0;
466 int partial_frame_size = 3 * 80;
471 ret =
avio_read(s->
pb, partial_frame, partial_frame_size);
475 if (ret < partial_frame_size) {
494 unsigned state, marker_pos = 0;
502 while ((state & 0xffffff7f) != 0x1f07003f) {
507 if (state == 0x003f0700 || state == 0xff3f0700)
509 if (state == 0xff3f0701 &&
avio_tell(s->
pb) - marker_pos == 80) {
527 "Can't determine profile of DV input stream.\n");
533 c->dv_demux->sys->time_base);
563 int64_t timestamp,
int flags)
585 unsigned state, marker_pos = 0;
588 int secondary_matches = 0;
595 if ((state & 0xffffff7f) == 0x1f07003f)
599 if ((state & 0xff07ff7f) == 0x1f07003f)
601 if (state == 0x003f0700 || state == 0xff3f0700)
603 if (state == 0xff3f0701 && i - marker_pos == 80)
605 state = (state << 8) | p->
buf[i];
608 if (matches && p->
buf_size / matches < 1024 * 1024) {
610 (secondary_matches >= 10 &&
611 p->
buf_size / secondary_matches < 24000))
619 #if CONFIG_DV_DEMUXER
629 .extensions =
"dv,dif",
static int shift(int a, int b)
int64_t pos
byte position in stream, -1 if unknown
#define DV_MAX_FRAME_SIZE
largest possible DV frame, in bytes (1080i50)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
AVCodecContext * codec
Codec context associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int index
stream index in AVFormatContext
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int64_t data_offset
offset of the first packet
#define AV_CH_LAYOUT_STEREO
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
uint8_t audio_buf[4][8192]
static const uint8_t offset[511][2]
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static av_cold int read_close(AVFormatContext *ctx)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void * priv_data
Format private data.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int flags
A combination of AV_PKT_FLAG values.
uint64_t channel_layout
Audio channel layout.
int buf_size
Size of buf except extra allocated bytes.
#define FF_ARRAY_ELEMS(a)
const DVprofile * avpriv_dv_codec_profile(AVCodecContext *codec)
int bit_rate
the average bitrate
DVDemuxContext * dv_demux
static int read_header(FFV1Context *f)
enum AVMediaType codec_type
int sample_rate
samples per second
main external API structure.
#define AV_TIMECODE_STR_SIZE
AVIOContext * pb
I/O context.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
rational number numerator/denominator
This structure contains the data a format has to probe a file.
const uint8_t(* audio_shuffle)[9]
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
uint8_t buf[DV_MAX_FRAME_SIZE]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
#define AVERROR_INVALIDDATA
int channels
number of audio channels
const DVprofile * avpriv_dv_frame_profile(const DVprofile *sys, const uint8_t *frame, unsigned buf_size)
int bit_rate
Decoding: total stream bitrate in bit/s, 0 if not available.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
char * av_timecode_make_smpte_tc_string(char *buf, uint32_t tcsmpte, int prevent_df)
Get the timecode string from the SMPTE timecode format.