FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
v210.c
Go to the documentation of this file.
1 /*
2  * Raw v210 video demuxer
3  * Copyright (c) 2015 Tiancheng "Timothy" Gu
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/imgutils.h"
23 #include "libavutil/parseutils.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/opt.h"
26 #include "internal.h"
27 #include "avformat.h"
28 
29 typedef struct V210DemuxerContext {
30  const AVClass *class; /**< Class for private options. */
31  int width, height; /**< Integers describing video size, set by a private option. */
32  AVRational framerate; /**< AVRational describing framerate, set by a private option. */
34 
35 // v210 frame width is padded to multiples of 48
36 #define GET_PACKET_SIZE(w, h) (((w + 47) / 48) * 48 * h * 8 / 3)
37 
39 {
41  AVStream *st;
42  int ret;
43 
44  st = avformat_new_stream(ctx, NULL);
45  if (!st)
46  return AVERROR(ENOMEM);
47 
49 
51 
53 
54  ret = av_image_check_size(s->width, s->height, 0, ctx);
55  if (ret < 0)
56  return ret;
57  st->codecpar->width = s->width;
58  st->codecpar->height = s->height;
61  ctx->packet_size = GET_PACKET_SIZE(s->width, s->height);
63  (AVRational){8,1}, st->time_base);
64 
65  return 0;
66 }
67 
68 
70 {
71  int ret;
72 
73  ret = av_get_packet(s->pb, pkt, s->packet_size);
74  pkt->pts = pkt->dts = pkt->pos / s->packet_size;
75 
76  pkt->stream_index = 0;
77  if (ret < 0)
78  return ret;
79  return 0;
80 }
81 
82 #define OFFSET(x) offsetof(V210DemuxerContext, x)
83 #define DEC AV_OPT_FLAG_DECODING_PARAM
84 static const AVOption v210_options[] = {
85  { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
86  { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
87  { NULL },
88 };
89 
90 #if CONFIG_V210_DEMUXER
91 static const AVClass v210_demuxer_class = {
92  .class_name = "v210 demuxer",
93  .item_name = av_default_item_name,
94  .option = v210_options,
95  .version = LIBAVUTIL_VERSION_INT,
96 };
97 
99  .name = "v210",
100  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
101  .priv_data_size = sizeof(V210DemuxerContext),
105  .extensions = "v210",
106  .raw_codec_id = AV_CODEC_ID_V210,
107  .priv_class = &v210_demuxer_class,
108 };
109 #endif // CONFIG_V210_DEMUXER
110 
111 #if CONFIG_V210X_DEMUXER
112 static const AVClass v210x_demuxer_class = {
113  .class_name = "v210x demuxer",
114  .item_name = av_default_item_name,
115  .option = v210_options,
116  .version = LIBAVUTIL_VERSION_INT,
117 };
118 
120  .name = "v210x",
121  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
122  .priv_data_size = sizeof(V210DemuxerContext),
126  .extensions = "yuv10",
127  .raw_codec_id = AV_CODEC_ID_V210X,
128  .priv_class = &v210x_demuxer_class,
129 };
130 #endif // CONFIG_V210X_DEMUXER
unsigned int packet_size
Definition: avformat.h:1475
#define NULL
Definition: coverity.c:32
AVOption.
Definition: opt.h:246
misc image utilities
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1465
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:4882
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3900
int num
Numerator.
Definition: rational.h:59
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static AVPacket pkt
Format I/O context.
Definition: avformat.h:1351
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
int width
Video only.
Definition: avcodec.h:3966
AVOptions.
static int v210_read_header(AVFormatContext *ctx)
Definition: v210.c:38
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4455
AVRational framerate
AVRational describing framerate, set by a private option.
Definition: v210.c:32
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.
Definition: utils.c:310
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3929
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
#define AVERROR(e)
Definition: error.h:43
int height
Integers describing video size, set by a private option.
Definition: v210.c:31
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3896
static const AVOption v210_options[]
Definition: v210.c:84
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:282
#define width
#define DEC
Definition: v210.c:83
AVInputFormat ff_v210_demuxer
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
Stream structure.
Definition: avformat.h:874
static int v210_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: v210.c:69
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVIOContext * pb
I/O context.
Definition: avformat.h:1393
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:470
Rational number (pair of numerator and denominator).
Definition: rational.h:58
offset must point to AVRational
Definition: opt.h:236
offset must point to two consecutive integers
Definition: opt.h:233
misc parsing utilities
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:693
#define flags(name, subs,...)
Definition: cbs_av1.c:596
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:380
Main libavformat public API header.
#define OFFSET(x)
Definition: v210.c:82
AVInputFormat ff_v210x_demuxer
int den
Denominator.
Definition: rational.h:60
#define GET_PACKET_SIZE(w, h)
Definition: v210.c:36
struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1363
void * priv_data
Format private data.
Definition: avformat.h:1379
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1444
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:647
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1021
int stream_index
Definition: avcodec.h:1447
This structure stores compressed data.
Definition: avcodec.h:1422
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:391
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1438