2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
15 #include "./video_reader.h"
17 static const char *const kIVFSignature = "DKIF";
19 struct VpxVideoReaderStruct {
27 VpxVideoReader *vpx_video_reader_open(const char *filename) {
29 VpxVideoReader *reader = NULL;
30 FILE *const file = fopen(filename, "rb");
32 return NULL; // Can't open file
34 if (fread(header, 1, 32, file) != 32)
35 return NULL; // Can't read file header
37 if (memcmp(kIVFSignature, header, 4) != 0)
38 return NULL; // Wrong IVF signature
40 if (mem_get_le16(header + 4) != 0)
41 return NULL; // Wrong IVF version
43 reader = calloc(1, sizeof(*reader));
45 return NULL; // Can't allocate VpxVideoReader
48 reader->info.codec_fourcc = mem_get_le32(header + 8);
49 reader->info.frame_width = mem_get_le16(header + 12);
50 reader->info.frame_height = mem_get_le16(header + 14);
51 reader->info.time_base.numerator = mem_get_le32(header + 16);
52 reader->info.time_base.denominator = mem_get_le32(header + 20);
57 void vpx_video_reader_close(VpxVideoReader *reader) {
65 int vpx_video_reader_read_frame(VpxVideoReader *reader) {
66 return !ivf_read_frame(reader->file, &reader->buffer, &reader->frame_size,
67 &reader->buffer_size);
70 const uint8_t *vpx_video_reader_get_frame(VpxVideoReader *reader,
73 *size = reader->frame_size;
75 return reader->buffer;
78 const VpxVideoInfo *vpx_video_reader_get_info(VpxVideoReader *reader) {