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 #if FF_API_R_FRAME_RATE
96  st->r_frame_rate =
97 #endif
98  st->avg_frame_rate = framerate;
99  avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
100 
101 fail:
102  return ret;
103 }
104 
105 /* Note: Do not forget to add new entries to the Makefile as well. */
106 
107 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
108 #define DEC AV_OPT_FLAG_DECODING_PARAM
110  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
111  { NULL },
112 };
113 
114 #if CONFIG_LATM_DEMUXER
115 AVInputFormat ff_latm_demuxer = {
116  .name = "latm",
117  .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
118  .read_header = ff_raw_audio_read_header,
119  .read_packet = ff_raw_read_partial_packet,
120  .flags = AVFMT_GENERIC_INDEX,
121  .extensions = "latm",
122  .raw_codec_id = AV_CODEC_ID_AAC_LATM,
123 };
124 #endif
125 
126 #if CONFIG_MJPEG_DEMUXER
127 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", AV_CODEC_ID_MJPEG)
128 #endif
129 
130 #if CONFIG_MLP_DEMUXER
131 AVInputFormat ff_mlp_demuxer = {
132  .name = "mlp",
133  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
134  .read_header = ff_raw_audio_read_header,
135  .read_packet = ff_raw_read_partial_packet,
136  .flags = AVFMT_GENERIC_INDEX,
137  .extensions = "mlp",
138  .raw_codec_id = AV_CODEC_ID_MLP,
139 };
140 #endif
141 
142 #if CONFIG_TRUEHD_DEMUXER
143 AVInputFormat ff_truehd_demuxer = {
144  .name = "truehd",
145  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
146  .read_header = ff_raw_audio_read_header,
147  .read_packet = ff_raw_read_partial_packet,
148  .flags = AVFMT_GENERIC_INDEX,
149  .extensions = "thd",
150  .raw_codec_id = AV_CODEC_ID_TRUEHD,
151 };
152 #endif
153 
154 #if CONFIG_SHORTEN_DEMUXER
155 AVInputFormat ff_shorten_demuxer = {
156  .name = "shn",
157  .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
158  .read_header = ff_raw_audio_read_header,
159  .read_packet = ff_raw_read_partial_packet,
161  .extensions = "shn",
162  .raw_codec_id = AV_CODEC_ID_SHORTEN,
163 };
164 #endif
165 
166 #if CONFIG_VC1_DEMUXER
167 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
168 #endif
const AVOption ff_rawvideo_options[]
Definition: rawdec.c:109
char * framerate
String describing framerate, set by a private option.
Definition: rawdec.h:33
int size
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:153
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:940
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:3283
#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:916
Format I/O context.
Definition: avformat.h:828
AVOptions.
enum AVStreamParseType need_parsing
Definition: avformat.h:775
uint8_t * data
Definition: avcodec.h:915
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:56
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:88
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2736
int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:493
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:704
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:641
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:107
Stream structure.
Definition: avformat.h:622
NULL
Definition: eval.c:52
enum AVMediaType codec_type
Definition: avcodec.h:1347
enum AVCodecID codec_id
Definition: avcodec.h:1350
AVIOContext * pb
I/O context.
Definition: avformat.h:861
rational number numerator/denominator
Definition: rational.h:43
#define s1
Definition: regdef.h:38
misc parsing utilities
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:494
full parsing and repack
Definition: avformat.h:576
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:677
int den
denominator
Definition: rational.h:45
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
Definition: avformat.h:841
void * priv_data
Format private data.
Definition: avformat.h:848
#define DEC
Definition: rawdec.c:108
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:455
int stream_index
Definition: avcodec.h:917
int ff_raw_video_read_header(AVFormatContext *s)
Definition: rawdec.c:72
This structure stores compressed data.
Definition: avcodec.h:898