Improved aom_smooth_predictor_16x 32,16,8
[aom.git] / video_reader.c
blob6a96af967e3871e19c826f64236c96f5f388048d
1 /*
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.
12 #include <stdlib.h>
13 #include <string.h>
15 #include "./ivfdec.h"
16 #include "./video_reader.h"
18 #include "aom_ports/mem_ops.h"
20 static const char *const kIVFSignature = "DKIF";
22 struct AvxVideoReaderStruct {
23 AvxVideoInfo info;
24 FILE *file;
25 uint8_t *buffer;
26 size_t buffer_size;
27 size_t frame_size;
30 AvxVideoReader *aom_video_reader_open(const char *filename) {
31 char header[32];
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
46 reader->file = file;
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);
53 return reader;
56 void aom_video_reader_close(AvxVideoReader *reader) {
57 if (reader) {
58 fclose(reader->file);
59 free(reader->buffer);
60 free(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,
70 size_t *size) {
71 if (size) *size = reader->frame_size;
73 return reader->buffer;
76 const AvxVideoInfo *aom_video_reader_get_info(AvxVideoReader *reader) {
77 return &reader->info;