dtshddec.c
Go to the documentation of this file.
1 /*
2  * Raw DTS-HD 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 "libavutil/dict.h"
24 #include "avformat.h"
25 
26 #define AUPR_HDR 0x415550522D484452
27 #define AUPRINFO 0x41555052494E464F
28 #define BITSHVTB 0x4249545348565442
29 #define BLACKOUT 0x424C41434B4F5554
30 #define BRANCHPT 0x4252414E43485054
31 #define BUILDVER 0x4255494C44564552
32 #define CORESSMD 0x434F524553534D44
33 #define DTSHDHDR 0x4454534844484452
34 #define EXTSS_MD 0x45585453535f4d44
35 #define FILEINFO 0x46494C45494E464F
36 #define NAVI_TBL 0x4E4156492D54424C
37 #define STRMDATA 0x5354524D44415441
38 #define TIMECODE 0x54494D45434F4445
39 
40 typedef struct DTSHDDemuxContext {
41  uint64_t data_end;
43 
44 static int dtshd_probe(AVProbeData *p)
45 {
46  if (AV_RB64(p->buf) == DTSHDHDR)
47  return AVPROBE_SCORE_MAX;
48  return 0;
49 }
50 
52 {
53  DTSHDDemuxContext *dtshd = s->priv_data;
54  AVIOContext *pb = s->pb;
55  uint64_t chunk_type, chunk_size;
56  AVStream *st;
57  int ret;
58  char *value;
59 
60  st = avformat_new_stream(s, NULL);
61  if (!st)
62  return AVERROR(ENOMEM);
66 
67  while (!url_feof(pb)) {
68  chunk_type = avio_rb64(pb);
69  chunk_size = avio_rb64(pb);
70 
71  if (chunk_size < 4) {
72  av_log(s, AV_LOG_ERROR, "chunk size too small\n");
73  return AVERROR_INVALIDDATA;
74  }
75  if (chunk_size > ((uint64_t)1 << 61)) {
76  av_log(s, AV_LOG_ERROR, "chunk size too big\n");
77  return AVERROR_INVALIDDATA;
78  }
79 
80  switch (chunk_type) {
81  case STRMDATA:
82  dtshd->data_end = chunk_size + avio_tell(pb);
83  if (dtshd->data_end <= chunk_size)
84  return AVERROR_INVALIDDATA;
85  return 0;
86  break;
87  case FILEINFO:
88  if (chunk_size > INT_MAX)
89  goto skip;
90  value = av_malloc(chunk_size);
91  if (!value)
92  goto skip;
93  avio_read(pb, value, chunk_size);
94  value[chunk_size - 1] = 0;
95  av_dict_set(&s->metadata, "fileinfo", value,
97  break;
98  default:
99 skip:
100  ret = avio_skip(pb, chunk_size);
101  if (ret < 0)
102  return ret;
103  };
104  }
105 
106  return AVERROR_EOF;
107 }
108 
110 {
111  DTSHDDemuxContext *dtshd = s->priv_data;
112  int64_t size, left;
113  int ret;
114 
115  left = dtshd->data_end - avio_tell(s->pb);
116  size = FFMIN(left, 1024);
117  if (size <= 0)
118  return AVERROR_EOF;
119 
120  ret = av_get_packet(s->pb, pkt, size);
121  if (ret < 0)
122  return ret;
123 
124  pkt->stream_index = 0;
125 
126  return ret;
127 }
128 
130  .name = "dtshd",
131  .long_name = NULL_IF_CONFIG_SMALL("raw DTS-HD"),
132  .priv_data_size = sizeof(DTSHDDemuxContext),
137  .extensions = "dtshd",
138  .raw_codec_id = AV_CODEC_ID_DTS,
139 };
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AV_RB64
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
AVInputFormat ff_dtshd_demuxer
Definition: dtshddec.c:129
Format I/O context.
Definition: avformat.h:944
Public dictionary API.
static AVPacket pkt
Definition: demuxing.c:56
enum AVStreamParseType need_parsing
Definition: avformat.h:811
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
Definition: error.h:55
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.
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:675
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
full parsing and repack with timestamp and position generation by parser for raw this assumes that ea...
Definition: avformat.h:586
#define DTSHDHDR
Definition: dtshddec.c:33
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:478
AVDictionary * metadata
Definition: avformat.h:1092
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
struct DTSHDDemuxContext DTSHDDemuxContext
int size
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
#define FILEINFO
Definition: dtshddec.c:35
#define FFMIN(a, b)
Definition: common.h:58
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that&#39;s been allocated with av_malloc() and chilren.
Definition: dict.h:72
static int read_probe(AVProbeData *pd)
ret
Definition: avfilter.c:821
static int dtshd_read_header(AVFormatContext *s)
Definition: dtshddec.c:51
int url_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:280
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
enum AVMediaType codec_type
static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: dtshddec.c:109
enum AVCodecID codec_id
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:62
uint64_t data_end
Definition: dtshddec.c:41
double value
Definition: eval.c:82
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:353
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
static int dtshd_probe(AVProbeData *p)
Definition: dtshddec.c:44
static int flags
Definition: cpu.c:23
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
#define STRMDATA
Definition: dtshddec.c:37
Main libavformat public API header.
void * priv_data
Format private data.
Definition: avformat.h:964
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
This structure stores compressed data.