blob: af5fdd2f6c87ef8c367c020d29d45c04cc3c6009 [file] [log] [blame]
Timothy B. Terriberry44d89492010-05-26 18:27:51 -04001/*
Krishna Rapaka7319db52021-09-28 20:35:29 -07002 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
Timothy B. Terriberry44d89492010-05-26 18:27:51 -04003 *
Vibhoothi41c6dd72021-10-12 18:48:26 +00004 * This source code is subject to the terms of the BSD 3-Clause Clear License
5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6 * License was not distributed with this source code in the LICENSE file, you
7 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the
8 * Alliance for Open Media Patent License 1.0 was not distributed with this
9 * source code in the PATENTS file, you can obtain it at
10 * aomedia.org/license/patent-license/.
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040011 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -070012 * Based on code from the OggTheora software codec source code,
13 * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors.
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040014 */
James Zern0f512782013-12-15 18:40:23 -080015
James Zerne1cbb132018-08-22 14:10:36 -070016#ifndef AOM_COMMON_Y4MINPUT_H_
17#define AOM_COMMON_Y4MINPUT_H_
James Zern0f512782013-12-15 18:40:23 -080018
clang-format6c4d83e2016-08-08 19:03:30 -070019#include <stdio.h>
Yaowu Xuf883b422016-08-30 14:01:10 -070020#include "aom/aom_image.h"
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040021
James Zern25cfd8e2014-01-18 12:16:11 -080022#ifdef __cplusplus
23extern "C" {
24#endif
25
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040026typedef struct y4m_input y4m_input;
27
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040028/*The function used to perform chroma conversion.*/
clang-format6c4d83e2016-08-08 19:03:30 -070029typedef void (*y4m_convert_func)(y4m_input *_y4m, unsigned char *_dst,
30 unsigned char *_src);
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040031
John Koleszarc6b90392012-07-13 15:21:29 -070032struct y4m_input {
clang-format6c4d83e2016-08-08 19:03:30 -070033 int pic_w;
34 int pic_h;
35 int fps_n;
36 int fps_d;
37 int par_n;
38 int par_d;
39 char interlace;
40 int src_c_dec_h;
41 int src_c_dec_v;
42 int dst_c_dec_h;
43 int dst_c_dec_v;
44 char chroma_type[16];
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040045 /*The size of each converted frame buffer.*/
clang-format6c4d83e2016-08-08 19:03:30 -070046 size_t dst_buf_sz;
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040047 /*The amount to read directly into the converted frame buffer.*/
clang-format6c4d83e2016-08-08 19:03:30 -070048 size_t dst_buf_read_sz;
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040049 /*The size of the auxilliary buffer.*/
clang-format6c4d83e2016-08-08 19:03:30 -070050 size_t aux_buf_sz;
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040051 /*The amount to read into the auxilliary buffer.*/
clang-format6c4d83e2016-08-08 19:03:30 -070052 size_t aux_buf_read_sz;
53 y4m_convert_func convert;
54 unsigned char *dst_buf;
55 unsigned char *aux_buf;
Yaowu Xuf883b422016-08-30 14:01:10 -070056 enum aom_img_fmt aom_fmt;
clang-format6c4d83e2016-08-08 19:03:30 -070057 int bps;
58 unsigned int bit_depth;
Elliott Karpilovsky8d570412021-02-02 22:49:56 -080059 aom_color_range_t color_range;
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040060};
61
elliottkb63b5712018-09-17 11:20:20 -070062/**
Elliott Karpilovsky72961162021-01-19 18:17:26 -080063 * Open the input file, treating it as Y4M. |y4m_ctx| is filled in after
Elliott Karpilovsky48fe4c32021-01-12 18:49:54 -080064 * reading it. Note that |csp| should only be set for 420 input, and the input
65 * chroma is shifted if necessary. The code does not support the conversion
66 * from co-located to vertical. The |skip_buffer| indicates bytes that were
67 * previously read from |file|, to do input-type detection; this buffer will
68 * be read before the |file| is read. It is of size |num_skip|, which *must*
69 * be 8 or less.
70 *
71 * Returns 0 on success, -1 on failure.
elliottkb63b5712018-09-17 11:20:20 -070072 */
Elliott Karpilovsky48fe4c32021-01-12 18:49:54 -080073int y4m_input_open(y4m_input *y4m_ctx, FILE *file, char *skip_buffer,
74 int num_skip, aom_chroma_sample_position_t csp,
75 int only_420);
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040076void y4m_input_close(y4m_input *_y4m);
Yaowu Xuf883b422016-08-30 14:01:10 -070077int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, aom_image_t *img);
Timothy B. Terriberry44d89492010-05-26 18:27:51 -040078
James Zern25cfd8e2014-01-18 12:16:11 -080079#ifdef __cplusplus
80} // extern "C"
81#endif
82
James Zerne1cbb132018-08-22 14:10:36 -070083#endif // AOM_COMMON_Y4MINPUT_H_