1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2014 Tim Walker <tdskywalker@gmail.com>
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14cabdff1aSopenharmony_ci * Lesser General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci/**
22cabdff1aSopenharmony_ci * @file
23cabdff1aSopenharmony_ci * internal header for HEVC (de)muxer utilities
24cabdff1aSopenharmony_ci */
25cabdff1aSopenharmony_ci
26cabdff1aSopenharmony_ci#ifndef AVFORMAT_HEVC_H
27cabdff1aSopenharmony_ci#define AVFORMAT_HEVC_H
28cabdff1aSopenharmony_ci
29cabdff1aSopenharmony_ci#include <stdint.h>
30cabdff1aSopenharmony_ci#include "avio.h"
31cabdff1aSopenharmony_ci
32cabdff1aSopenharmony_ci/**
33cabdff1aSopenharmony_ci * Writes Annex B formatted HEVC NAL units to the provided AVIOContext.
34cabdff1aSopenharmony_ci *
35cabdff1aSopenharmony_ci * The NAL units are converted to an MP4-compatible format (start code prefixes
36cabdff1aSopenharmony_ci * are replaced by 4-byte size fields, as per ISO/IEC 14496-15).
37cabdff1aSopenharmony_ci *
38cabdff1aSopenharmony_ci * If filter_ps is non-zero, any HEVC parameter sets found in the input will be
39cabdff1aSopenharmony_ci * discarded, and *ps_count will be set to the number of discarded PS NAL units.
40cabdff1aSopenharmony_ci *
41cabdff1aSopenharmony_ci * @param pb address of the AVIOContext where the data shall be written
42cabdff1aSopenharmony_ci * @param buf_in address of the buffer holding the input data
43cabdff1aSopenharmony_ci * @param size size (in bytes) of the input buffer
44cabdff1aSopenharmony_ci * @param filter_ps whether to write parameter set NAL units to the output (0)
45cabdff1aSopenharmony_ci *        or to discard them (non-zero)
46cabdff1aSopenharmony_ci * @param ps_count address of the variable where the number of discarded
47cabdff1aSopenharmony_ci *        parameter set NAL units shall be written, may be NULL
48cabdff1aSopenharmony_ci * @return the amount (in bytes) of data written in case of success, a negative
49cabdff1aSopenharmony_ci *         value corresponding to an AVERROR code in case of failure
50cabdff1aSopenharmony_ci */
51cabdff1aSopenharmony_ciint ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
52cabdff1aSopenharmony_ci                       int size, int filter_ps, int *ps_count);
53cabdff1aSopenharmony_ci
54cabdff1aSopenharmony_ci/**
55cabdff1aSopenharmony_ci * Writes Annex B formatted HEVC NAL units to a data buffer.
56cabdff1aSopenharmony_ci *
57cabdff1aSopenharmony_ci * The NAL units are converted to an MP4-compatible format (start code prefixes
58cabdff1aSopenharmony_ci * are replaced by 4-byte size fields, as per ISO/IEC 14496-15).
59cabdff1aSopenharmony_ci *
60cabdff1aSopenharmony_ci * If filter_ps is non-zero, any HEVC parameter sets found in the input will be
61cabdff1aSopenharmony_ci * discarded, and *ps_count will be set to the number of discarded PS NAL units.
62cabdff1aSopenharmony_ci *
63cabdff1aSopenharmony_ci * On success, *size holds the size (in bytes) of the output data buffer.
64cabdff1aSopenharmony_ci *
65cabdff1aSopenharmony_ci * @param buf_in address of the buffer holding the input data
66cabdff1aSopenharmony_ci * @param size address of the variable holding the size (in bytes) of the input
67cabdff1aSopenharmony_ci *        buffer (on input) and of the output buffer (on success)
68cabdff1aSopenharmony_ci * @param buf_out on success, address of the variable holding the address of
69cabdff1aSopenharmony_ci *        the output buffer
70cabdff1aSopenharmony_ci * @param filter_ps whether to write parameter set NAL units to the output (0)
71cabdff1aSopenharmony_ci *        or to discard them (non-zero)
72cabdff1aSopenharmony_ci * @param ps_count address of the variable where the number of discarded
73cabdff1aSopenharmony_ci *        parameter set NAL units shall be written, may be NULL
74cabdff1aSopenharmony_ci * @return 0 in case of success, a negative value corresponding to an AVERROR
75cabdff1aSopenharmony_ci *         code in case of failure
76cabdff1aSopenharmony_ci * @note *buf_out will be treated as uninitialized on input and won't be freed.
77cabdff1aSopenharmony_ci */
78cabdff1aSopenharmony_ciint ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
79cabdff1aSopenharmony_ci                           int *size, int filter_ps, int *ps_count);
80cabdff1aSopenharmony_ci
81cabdff1aSopenharmony_ci/**
82cabdff1aSopenharmony_ci * Writes HEVC extradata (parameter sets, declarative SEI NAL units) to the
83cabdff1aSopenharmony_ci * provided AVIOContext.
84cabdff1aSopenharmony_ci *
85cabdff1aSopenharmony_ci * If the extradata is Annex B format, it gets converted to hvcC format before
86cabdff1aSopenharmony_ci * writing.
87cabdff1aSopenharmony_ci *
88cabdff1aSopenharmony_ci * @param pb address of the AVIOContext where the hvcC shall be written
89cabdff1aSopenharmony_ci * @param data address of the buffer holding the data needed to write the hvcC
90cabdff1aSopenharmony_ci * @param size size (in bytes) of the data buffer
91cabdff1aSopenharmony_ci * @param ps_array_completeness whether all parameter sets are in the hvcC (1)
92cabdff1aSopenharmony_ci *        or there may be additional parameter sets in the bitstream (0)
93cabdff1aSopenharmony_ci * @return >=0 in case of success, a negative value corresponding to an AVERROR
94cabdff1aSopenharmony_ci *         code in case of failure
95cabdff1aSopenharmony_ci */
96cabdff1aSopenharmony_ciint ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data,
97cabdff1aSopenharmony_ci                       int size, int ps_array_completeness);
98cabdff1aSopenharmony_ci
99cabdff1aSopenharmony_ci#endif /* AVFORMAT_HEVC_H */
100