libavformat/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 FFmpeg.
7  *
8  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 #include "libavutil/avassert.h"
31 
32 #define RAW_PACKET_SIZE 1024
33 
35 {
36  int ret, size;
37 
38  size = RAW_PACKET_SIZE;
39 
40  if (av_new_packet(pkt, size) < 0)
41  return AVERROR(ENOMEM);
42 
43  pkt->pos= avio_tell(s->pb);
44  pkt->stream_index = 0;
45  ret = ffio_read_partial(s->pb, pkt->data, size);
46  if (ret < 0) {
47  av_free_packet(pkt);
48  return ret;
49  }
50  av_shrink_packet(pkt, ret);
51  return ret;
52 }
53 
55 {
57  if (!st)
58  return AVERROR(ENOMEM);
62  st->start_time = 0;
63  /* the parameters will be extracted from the compressed bitstream */
64 
65  return 0;
66 }
67 
68 /* MPEG-1/H.263 input */
70 {
71  AVStream *st;
73  int ret = 0;
74 
75 
76  st = avformat_new_stream(s, NULL);
77  if (!st) {
78  ret = AVERROR(ENOMEM);
79  goto fail;
80  }
81 
85 
86  st->codec->time_base = av_inv_q(s1->framerate);
87  avpriv_set_pts_info(st, 64, 1, 1200000);
88 
89 fail:
90  return ret;
91 }
92 
93 /* Note: Do not forget to add new entries to the Makefile as well. */
94 
95 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
96 #define DEC AV_OPT_FLAG_DECODING_PARAM
98  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC},
99  { NULL },
100 };
101 
102 #if CONFIG_LATM_DEMUXER
103 AVInputFormat ff_latm_demuxer = {
104  .name = "latm",
105  .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
106  .read_header = ff_raw_audio_read_header,
107  .read_packet = ff_raw_read_partial_packet,
108  .flags = AVFMT_GENERIC_INDEX,
109  .extensions = "latm",
110  .raw_codec_id = AV_CODEC_ID_AAC_LATM,
111 };
112 #endif
113 
114 #if CONFIG_MJPEG_DEMUXER
115 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG)
116 #endif
117 
118 #if CONFIG_MLP_DEMUXER
119 AVInputFormat ff_mlp_demuxer = {
120  .name = "mlp",
121  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
122  .read_header = ff_raw_audio_read_header,
123  .read_packet = ff_raw_read_partial_packet,
124  .flags = AVFMT_GENERIC_INDEX,
125  .extensions = "mlp",
126  .raw_codec_id = AV_CODEC_ID_MLP,
127 };
128 #endif
129 
130 #if CONFIG_TRUEHD_DEMUXER
131 AVInputFormat ff_truehd_demuxer = {
132  .name = "truehd",
133  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
134  .read_header = ff_raw_audio_read_header,
135  .read_packet = ff_raw_read_partial_packet,
136  .flags = AVFMT_GENERIC_INDEX,
137  .extensions = "thd",
138  .raw_codec_id = AV_CODEC_ID_TRUEHD,
139 };
140 #endif
141 
142 #if CONFIG_SHORTEN_DEMUXER
143 AVInputFormat ff_shorten_demuxer = {
144  .name = "shn",
145  .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
146  .read_header = ff_raw_audio_read_header,
147  .read_packet = ff_raw_read_partial_packet,
149  .extensions = "shn",
150  .raw_codec_id = AV_CODEC_ID_SHORTEN,
151 };
152 #endif
153 
154 #if CONFIG_VC1_DEMUXER
155 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
156 #endif
const AVOption ff_rawvideo_options[]
#define AVFMT_NOBINSEARCH
Format does not allow to fallback to binary search via read_timestamp.
Definition: avformat.h:358
const char * s
Definition: avisynth_c.h:668
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
AVOption.
Definition: opt.h:251
int64_t pos
byte position in stream, -1 if unknown
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:97
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.
#define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)
Definition: rawdec.h:52
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Format I/O context.
Definition: avformat.h:944
AVOptions.
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.
uint8_t * data
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
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:73
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
simple assert() macros that are a bit more flexible than ISO C assert().
int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:526
int size
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
ret
Definition: avfilter.c:821
int ff_raw_audio_read_header(AVFormatContext *s)
#define RAW_PACKET_SIZE
#define OFFSET(x)
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define AVFMT_NOGENSEARCH
Format does not allow to fallback to generic search.
Definition: avformat.h:359
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:353
offset must point to AVRational
Definition: opt.h:233
#define s1
Definition: regdef.h:38
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
misc parsing utilities
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:500
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
Main libavformat public API header.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:689
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
Definition: avformat.h:957
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:360
AVRational framerate
AVRational describing framerate, set by a private option.
Definition: rawdec.h:33
void * priv_data
Format private data.
Definition: avformat.h:964
#define DEC
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
int ff_raw_video_read_header(AVFormatContext *s)
This structure stores compressed data.