FFmpeg: libavformat/av1dec.c Source File
Go to the documentation of this file. 1 /*
2 * AV1 Annex B demuxer
3 * Copyright (c) 2019 James Almer <jamrial@gmail.com>
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 "config.h"
23
31
39
40 //return < 0 if we need more data
42 {
45 *seq = 1;
46 return -1;
52 return -1;
53 default:
54 break;
55 }
56 return 0;
57 }
58
60 {
66
69 "not found. This is a bug, please report it.\n");
71 }
72
74 if (!st)
77
81
83 // taken from rawvideo demuxers
85
89
93
97
98 return 0;
99 }
100
102 {
104
106 return 0;
107 }
108
109 #define DEC AV_OPT_FLAG_DECODING_PARAM
110 #define OFFSET(x) offsetof(AV1DemuxContext, x)
114 };
115 #undef OFFSET
116
118 .
class_name =
"AV1 Annex B/low overhead OBU demuxer",
122 };
123
124 #if CONFIG_AV1_DEMUXER
125
130 do {
133 more = byte & 0x80;
135 if (
i <= 3 || (
i == 4 &&
bits < (1 << 4)))
139 if (++
i == 8 && more)
143 } while (more);
145 }
146
147 static int read_obu(
const uint8_t *buf,
int size, int64_t *obu_size,
int *
type)
148 {
149 int start_pos, temporal_id, spatial_id;
151
153 type, &temporal_id, &spatial_id);
156
157 return 0;
158 }
159
161 {
164 int64_t obu_size;
165 uint32_t temporal_unit_size, frame_unit_size, obu_unit_size;
166 int seq = 0;
168
171
172 ret = leb(pb, &temporal_unit_size);
174 return 0;
176 ret = leb(pb, &frame_unit_size);
177 if (
ret < 0 || ((int64_t)frame_unit_size +
ret) > temporal_unit_size)
178 return 0;
180 ret = leb(pb, &obu_unit_size);
181 if (
ret < 0 || ((int64_t)obu_unit_size +
ret) >= frame_unit_size)
182 return 0;
184
185 frame_unit_size -= obu_unit_size +
ret;
186
189 return 0;
190
191 // Check that the first OBU is a Temporal Delimiter.
193 if (ret < 0 || type != AV1_OBU_TEMPORAL_DELIMITER || obu_size > 0)
194 return 0;
195 cnt += obu_unit_size;
196
197 do {
198 ret = leb(pb, &obu_unit_size);
199 if (
ret < 0 || ((int64_t)obu_unit_size +
ret) > frame_unit_size)
200 return 0;
202
205 return 0;
206
209 return 0;
210 cnt += obu_unit_size;
211
215
216 frame_unit_size -= obu_unit_size +
ret;
217 } while (frame_unit_size);
218
219 return 0;
220 }
221
223 {
225 uint32_t obu_unit_size;
227
228 retry:
230 if (
c->temporal_unit_size ||
c->frame_unit_size)
232 goto end;
233 }
234
235 if (!
c->temporal_unit_size) {
236 len = leb(
s->pb, &
c->temporal_unit_size);
238 }
239
240 if (!
c->frame_unit_size) {
241 len = leb(
s->pb, &
c->frame_unit_size);
242 if (
len < 0 || ((int64_t)
c->frame_unit_size +
len) >
c->temporal_unit_size)
244 c->temporal_unit_size -=
len;
245 }
246
247 len = leb(
s->pb, &obu_unit_size);
248 if (
len < 0 || ((int64_t)obu_unit_size +
len) >
c->frame_unit_size)
250
254 if (
ret != obu_unit_size)
256
257 c->temporal_unit_size -= obu_unit_size +
len;
258 c->frame_unit_size -= obu_unit_size +
len;
259
260 end:
264 "av1_frame_merge filter\n");
266 }
267
271 "send output packet\n");
272
274 goto retry;
275
277 }
278
288 .extensions = "obu",
291 };
292 #endif
293
294 #if CONFIG_OBU_DEMUXER
295 //For low overhead obu, we can't foresee the obu size before we parsed the header.
296 //So, we can't use parse_obu_header here, since it will check size <= buf_size
297 //see c27c7b49dc for more details
298 static int read_obu_with_size(
const uint8_t *buf,
int buf_size, int64_t *obu_size,
int *
type)
299 {
301 int ret, extension_flag, start_pos;
303
307
308 if (
get_bits1(&gb) != 0)
// obu_forbidden_bit
310
316
317 if (extension_flag) {
320 skip_bits(&gb, 3);
// extension_header_reserved_3bits
321 }
322
324 if (*obu_size > INT_MAX)
326
329
331
332 size = *obu_size + start_pos;
336 }
337
339 {
340 int64_t obu_size;
341 int seq = 0;
343
344 // Check that the first OBU is a Temporal Delimiter.
347 return 0;
348
349 while (1) {
351 if (
ret < 0 || obu_size <= 0)
352 return 0;
354
358 }
359 return 0;
360 }
361
363 {
366 int64_t obu_size;
369
375
380 }
382
387 }
388 return 0;
389 }
390
392 {
395
396 if (
s->io_repositioned) {
398 s->io_repositioned = 0;
399 }
400 while (1) {
402 /* In case of AVERROR_EOF we need to flush the BSF. Conveniently
403 * obu_get_packet() returns a blank pkt in this case which
404 * can be used to signal that the BSF should be flushed. */
410 "av1_frame_merge filter\n");
412 }
416 "send output packet\n");
418 break;
419 }
420
422 }
423
433 .extensions = "obu",
436 };
437 #endif
static int get_bits_left(GetBitContext *gb)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
#define AVERROR_EOF
End of file.
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
static int get_bits_count(const GetBitContext *s)
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
int error
contains the error code or 0 if no error happened
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
int buf_size
Size of buf except extra allocated bytes.
@ AV1_OBU_TEMPORAL_DELIMITER
The bitstream filter state.
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_cold int read_close(AVFormatContext *ctx)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int parse_obu_header(const uint8_t *buf, int buf_size, int64_t *obu_size, int *start_pos, int *type, int *temporal_id, int *spatial_id)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
const char * av_default_item_name(void *ptr)
Return the context name.
static unsigned int get_bits1(GetBitContext *s)
This structure contains the data a format has to probe a file.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
@ AV1_OBU_SEQUENCE_HEADER
static const uint8_t header[24]
int avio_r8(AVIOContext *s)
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
static void skip_bits1(GetBitContext *s)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
#define i(width, name, range_min, range_max)
void ffio_init_context(FFIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_INPUT_BUFFER_PADDING_SIZE
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
uint32_t temporal_unit_size
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int eof_reached
true if was unable to read due to error or eof
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
#define flags(name, subs,...)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
#define MAX_OBU_HEADER_SIZE
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Wed Aug 24 2022 21:37:27 for FFmpeg by
doxygen
1.8.17