2014-02-06 06:34:46 +04:00
|
|
|
/*
|
2016-09-02 00:32:49 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2014-02-06 06:34:46 +04:00
|
|
|
*
|
2016-09-02 00:32:49 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2014-02-06 06:34:46 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "./ivfdec.h"
|
|
|
|
#include "./video_reader.h"
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "aom_ports/mem_ops.h"
|
2014-02-27 04:32:09 +04:00
|
|
|
|
2014-02-06 06:34:46 +04:00
|
|
|
static const char *const kIVFSignature = "DKIF";
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
struct AvxVideoReaderStruct {
|
|
|
|
AvxVideoInfo info;
|
2014-02-06 06:34:46 +04:00
|
|
|
FILE *file;
|
|
|
|
uint8_t *buffer;
|
|
|
|
size_t buffer_size;
|
|
|
|
size_t frame_size;
|
|
|
|
};
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
AvxVideoReader *aom_video_reader_open(const char *filename) {
|
2014-02-06 06:34:46 +04:00
|
|
|
char header[32];
|
2016-08-31 00:01:10 +03:00
|
|
|
AvxVideoReader *reader = NULL;
|
2014-02-06 06:34:46 +04:00
|
|
|
FILE *const file = fopen(filename, "rb");
|
2016-08-09 05:03:30 +03:00
|
|
|
if (!file) return NULL; // Can't open file
|
2014-02-06 06:34:46 +04:00
|
|
|
|
2016-08-09 05:03:30 +03:00
|
|
|
if (fread(header, 1, 32, file) != 32) return NULL; // Can't read file header
|
2014-02-06 06:34:46 +04:00
|
|
|
|
|
|
|
if (memcmp(kIVFSignature, header, 4) != 0)
|
|
|
|
return NULL; // Wrong IVF signature
|
|
|
|
|
2016-08-09 05:03:30 +03:00
|
|
|
if (mem_get_le16(header + 4) != 0) return NULL; // Wrong IVF version
|
2014-02-06 06:34:46 +04:00
|
|
|
|
|
|
|
reader = calloc(1, sizeof(*reader));
|
2016-08-31 00:01:10 +03:00
|
|
|
if (!reader) return NULL; // Can't allocate AvxVideoReader
|
2014-02-06 06:34:46 +04:00
|
|
|
|
|
|
|
reader->file = file;
|
|
|
|
reader->info.codec_fourcc = mem_get_le32(header + 8);
|
|
|
|
reader->info.frame_width = mem_get_le16(header + 12);
|
|
|
|
reader->info.frame_height = mem_get_le16(header + 14);
|
|
|
|
reader->info.time_base.numerator = mem_get_le32(header + 16);
|
|
|
|
reader->info.time_base.denominator = mem_get_le32(header + 20);
|
|
|
|
|
|
|
|
return reader;
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
void aom_video_reader_close(AvxVideoReader *reader) {
|
2014-02-06 06:34:46 +04:00
|
|
|
if (reader) {
|
|
|
|
fclose(reader->file);
|
|
|
|
free(reader->buffer);
|
|
|
|
free(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
int aom_video_reader_read_frame(AvxVideoReader *reader) {
|
2014-02-06 06:34:46 +04:00
|
|
|
return !ivf_read_frame(reader->file, &reader->buffer, &reader->frame_size,
|
|
|
|
&reader->buffer_size);
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
const uint8_t *aom_video_reader_get_frame(AvxVideoReader *reader,
|
2014-02-06 06:34:46 +04:00
|
|
|
size_t *size) {
|
2016-08-09 05:03:30 +03:00
|
|
|
if (size) *size = reader->frame_size;
|
2014-02-06 06:34:46 +04:00
|
|
|
|
|
|
|
return reader->buffer;
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
const AvxVideoInfo *aom_video_reader_get_info(AvxVideoReader *reader) {
|
2014-02-06 06:34:46 +04:00
|
|
|
return &reader->info;
|
|
|
|
}
|