2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
16 #include "./video_reader.h"
18 #include "aom_ports/mem_ops.h"
20 static const char *const kIVFSignature
= "DKIF";
22 struct AvxVideoReaderStruct
{
30 AvxVideoReader
*aom_video_reader_open(const char *filename
) {
32 AvxVideoReader
*reader
= NULL
;
33 FILE *const file
= fopen(filename
, "rb");
34 if (!file
) return NULL
; // Can't open file
36 if (fread(header
, 1, 32, file
) != 32) return NULL
; // Can't read file header
38 if (memcmp(kIVFSignature
, header
, 4) != 0)
39 return NULL
; // Wrong IVF signature
41 if (mem_get_le16(header
+ 4) != 0) return NULL
; // Wrong IVF version
43 reader
= (AvxVideoReader
*)calloc(1, sizeof(*reader
));
44 if (!reader
) return NULL
; // Can't allocate AvxVideoReader
47 reader
->info
.codec_fourcc
= mem_get_le32(header
+ 8);
48 reader
->info
.frame_width
= mem_get_le16(header
+ 12);
49 reader
->info
.frame_height
= mem_get_le16(header
+ 14);
50 reader
->info
.time_base
.numerator
= mem_get_le32(header
+ 16);
51 reader
->info
.time_base
.denominator
= mem_get_le32(header
+ 20);
56 void aom_video_reader_close(AvxVideoReader
*reader
) {
64 int aom_video_reader_read_frame(AvxVideoReader
*reader
) {
65 return !ivf_read_frame(reader
->file
, &reader
->buffer
, &reader
->frame_size
,
66 &reader
->buffer_size
);
69 const uint8_t *aom_video_reader_get_frame(AvxVideoReader
*reader
,
71 if (size
) *size
= reader
->frame_size
;
73 return reader
->buffer
;
76 const AvxVideoInfo
*aom_video_reader_get_info(AvxVideoReader
*reader
) {