1 /* 2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved. 3 * 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. 10 * 11 * Based on code from the OggTheora software codec source code, 12 * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors. 13 */ 14 15 #ifndef AOM_COMMON_Y4MINPUT_H_ 16 #define AOM_COMMON_Y4MINPUT_H_ 17 18 #include <stdio.h> 19 #include "aom/aom_image.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 typedef struct y4m_input y4m_input; 26 27 /*The function used to perform chroma conversion.*/ 28 typedef void (*y4m_convert_func)(y4m_input *_y4m, unsigned char *_dst, 29 unsigned char *_src); 30 31 struct y4m_input { 32 int pic_w; 33 int pic_h; 34 int fps_n; 35 int fps_d; 36 int par_n; 37 int par_d; 38 char interlace; 39 int src_c_dec_h; 40 int src_c_dec_v; 41 int dst_c_dec_h; 42 int dst_c_dec_v; 43 char chroma_type[16]; 44 /*The size of each converted frame buffer.*/ 45 size_t dst_buf_sz; 46 /*The amount to read directly into the converted frame buffer.*/ 47 size_t dst_buf_read_sz; 48 /*The size of the auxilliary buffer.*/ 49 size_t aux_buf_sz; 50 /*The amount to read into the auxilliary buffer.*/ 51 size_t aux_buf_read_sz; 52 y4m_convert_func convert; 53 unsigned char *dst_buf; 54 unsigned char *aux_buf; 55 enum aom_img_fmt aom_fmt; 56 int bps; 57 unsigned int bit_depth; 58 aom_color_range_t color_range; 59 }; 60 61 /** 62 * Open the input file, treating it as Y4M. |y4m_ctx| is filled in after 63 * reading it. Note that |csp| should only be set for 420 input, and the input 64 * chroma is shifted if necessary. The code does not support the conversion 65 * from co-located to vertical. The |skip_buffer| indicates bytes that were 66 * previously read from |file|, to do input-type detection; this buffer will 67 * be read before the |file| is read. It is of size |num_skip|, which *must* 68 * be 8 or less. 69 * 70 * Returns 0 on success, -1 on failure. 71 */ 72 int y4m_input_open(y4m_input *y4m_ctx, FILE *file, char *skip_buffer, 73 int num_skip, aom_chroma_sample_position_t csp, 74 int only_420); 75 void y4m_input_close(y4m_input *_y4m); 76 int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, aom_image_t *img); 77 78 #ifdef __cplusplus 79 } // extern "C" 80 #endif 81 82 #endif // AOM_COMMON_Y4MINPUT_H_ 83