xref: /aosp_15_r20/external/libaom/common/webmenc.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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 #ifndef AOM_COMMON_WEBMENC_H_
12 #define AOM_COMMON_WEBMENC_H_
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 
17 #include "tools_common.h"
18 #include "aom/aom_encoder.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 struct WebmOutputContext {
25   int debug;
26   FILE *stream;
27   int64_t last_pts_ns;
28   void *writer;
29   void *segment;
30 };
31 
32 /* Stereo 3D packed frame format */
33 enum {
34   STEREO_FORMAT_MONO = 0,
35   STEREO_FORMAT_LEFT_RIGHT = 1,
36   STEREO_FORMAT_BOTTOM_TOP = 2,
37   STEREO_FORMAT_TOP_BOTTOM = 3,
38   STEREO_FORMAT_RIGHT_LEFT = 11
39 } UENUM1BYTE(stereo_format_t);
40 
41 // Simplistic mechanism to extract encoder settings, without having
42 // to re-invoke the entire flag-parsing logic. It lists the codec version
43 // and then copies the arguments as-is from argv, but skips the binary name,
44 // any arguments that match the input filename, and the output flags "-o"
45 // and "--output" (and the following argument for those flags). The caller
46 // is responsible for free-ing the returned string. If there is insufficient
47 // memory, it returns nullptr.
48 char *extract_encoder_settings(const char *version, const char **argv, int argc,
49                                const char *input_fname);
50 
51 // The following functions wrap libwebm's mkvmuxer. All functions return 0 upon
52 // success, or -1 upon failure.
53 
54 int write_webm_file_header(struct WebmOutputContext *webm_ctx,
55                            aom_codec_ctx_t *encoder_ctx,
56                            const aom_codec_enc_cfg_t *cfg,
57                            stereo_format_t stereo_fmt, unsigned int fourcc,
58                            const struct AvxRational *par,
59                            const char *encoder_settings);
60 
61 int write_webm_block(struct WebmOutputContext *webm_ctx,
62                      const aom_codec_enc_cfg_t *cfg,
63                      const aom_codec_cx_pkt_t *pkt);
64 
65 int write_webm_file_footer(struct WebmOutputContext *webm_ctx);
66 
67 #ifdef __cplusplus
68 }  // extern "C"
69 #endif
70 
71 #endif  // AOM_COMMON_WEBMENC_H_
72