Libav
rawdec.c
Go to the documentation of this file.
1 /*
2  * RAW demuxers
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2005 Alex Beregszaszi
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "avformat.h"
24 #include "internal.h"
25 #include "avio_internal.h"
26 #include "rawdec.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/pixdesc.h"
30 
31 #define RAW_PACKET_SIZE 1024
32 
34 {
35  int ret, size;
36 
37  size = RAW_PACKET_SIZE;
38 
39  if (av_new_packet(pkt, size) < 0)
40  return AVERROR(ENOMEM);
41 
42  pkt->pos= avio_tell(s->pb);
43  pkt->stream_index = 0;
44  ret = ffio_read_partial(s->pb, pkt->data, size);
45  if (ret < 0) {
46  av_free_packet(pkt);
47  return ret;
48  } else if (ret < size) {
49  /* initialize end of packet for partial reads to avoid reading
50  * uninitialized data on allowed overreads */
51  memset(pkt->data + ret, 0, FF_INPUT_BUFFER_PADDING_SIZE);
52  }
53  pkt->size = ret;
54  return ret;
55 }
56 
58 {
60  if (!st)
61  return AVERROR(ENOMEM);
65  st->start_time = 0;
66  /* the parameters will be extracted from the compressed bitstream */
67 
68  return 0;
69 }
70 
71 /* MPEG-1/H.263 input */
73 {
74  AVStream *st;
76  AVRational framerate;
77  int ret = 0;
78 
79 
80  st = avformat_new_stream(s, NULL);
81  if (!st) {
82  ret = AVERROR(ENOMEM);
83  goto fail;
84  }
85 
89 
90  if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
91  av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
92  goto fail;
93  }
94 
95  st->avg_frame_rate = framerate;
96  avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
97 
98 fail:
99  return ret;
100 }
101 
102 /* Note: Do not forget to add new entries to the Makefile as well. */
103 
104 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
105 #define DEC AV_OPT_FLAG_DECODING_PARAM
107  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
108  { NULL },
109 };
110 
111 #if CONFIG_LATM_DEMUXER
112 AVInputFormat ff_latm_demuxer = {
113  .name = "latm",
114  .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
115  .read_header = ff_raw_audio_read_header,
116  .read_packet = ff_raw_read_partial_packet,
117  .flags = AVFMT_GENERIC_INDEX,
118  .extensions = "latm",
119  .raw_codec_id = AV_CODEC_ID_AAC_LATM,
120 };
121 #endif
122 
123 #if CONFIG_MJPEG_DEMUXER
124 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", AV_CODEC_ID_MJPEG)
125 #endif
126 
127 #if CONFIG_MLP_DEMUXER
128 AVInputFormat ff_mlp_demuxer = {
129  .name = "mlp",
130  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
131  .read_header = ff_raw_audio_read_header,
132  .read_packet = ff_raw_read_partial_packet,
133  .flags = AVFMT_GENERIC_INDEX,
134  .extensions = "mlp",
135  .raw_codec_id = AV_CODEC_ID_MLP,
136 };
137 #endif
138 
139 #if CONFIG_TRUEHD_DEMUXER
140 AVInputFormat ff_truehd_demuxer = {
141  .name = "truehd",
142  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
143  .read_header = ff_raw_audio_read_header,
144  .read_packet = ff_raw_read_partial_packet,
145  .flags = AVFMT_GENERIC_INDEX,
146  .extensions = "thd",
147  .raw_codec_id = AV_CODEC_ID_TRUEHD,
148 };
149 #endif
150 
151 #if CONFIG_SHORTEN_DEMUXER
152 AVInputFormat ff_shorten_demuxer = {
153  .name = "shn",
154  .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
155  .read_header = ff_raw_audio_read_header,
156  .read_packet = ff_raw_read_partial_packet,
158  .extensions = "shn",
159  .raw_codec_id = AV_CODEC_ID_SHORTEN,
160 };
161 #endif
162 
163 #if CONFIG_VC1_DEMUXER
164 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
165 #endif
const AVOption ff_rawvideo_options[]
Definition: rawdec.c:106
char * framerate
String describing framerate, set by a private option.
Definition: rawdec.h:33
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:413
int size
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:122
AVOption.
Definition: opt.h:233
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1002
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:3208
#define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)
Definition: rawdec.h:52
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:974
Format I/O context.
Definition: avformat.h:871
AVOptions.
enum AVStreamParseType need_parsing
Definition: avformat.h:816
uint8_t * data
Definition: avcodec.h:973
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:80
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define AVERROR(e)
Definition: error.h:43
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawdec.c:33
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2662
int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:505
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:754
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:702
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:509
int ff_raw_audio_read_header(AVFormatContext *s)
Definition: rawdec.c:57
#define RAW_PACKET_SIZE
Definition: rawdec.c:31
#define OFFSET(x)
Definition: rawdec.c:104
Stream structure.
Definition: avformat.h:683
NULL
Definition: eval.c:55
enum AVMediaType codec_type
Definition: avcodec.h:1062
enum AVCodecID codec_id
Definition: avcodec.h:1065
AVIOContext * pb
I/O context.
Definition: avformat.h:913
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:414
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:408
rational number numerator/denominator
Definition: rational.h:43
misc parsing utilities
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:555
full parsing and repack
Definition: avformat.h:637
Main libavformat public API header.
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
Definition: avformat.h:727
int den
denominator
Definition: rational.h:45
struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:883
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:415
void * priv_data
Format private data.
Definition: avformat.h:899
#define DEC
Definition: rawdec.c:105
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:516
int stream_index
Definition: avcodec.h:975
int ff_raw_video_read_header(AVFormatContext *s)
Definition: rawdec.c:72
This structure stores compressed data.
Definition: avcodec.h:950