Debian Codegraph @

gst/mpegtsmux/gstbasetsmuxjpegxs.c

raw symbols SCIP
1 /* JPEG-XS support for MPEG-TS
2 *
3 * Copyright (C) <2024> Centricular ltd
4 * @author Edward Hervey <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 * SPDX-License-Identifier: LGPL-2.0-or-later
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <stdio.h>
29 #include "gstbasetsmuxjpegxs.h"
30 #include <string.h>
31 #include <gst/base/gstbytewriter.h>
32 #include <gst/gst.h>
33
34 #define GST_CAT_DEFAULT gst_base_ts_mux_debug
35
36 GstBuffer *
37 gst_base_ts_mux_prepare_jpegxs (GstBuffer * buf, GstBaseTsMuxPad * pad,
38 GstBaseTsMux * mux)
39 {
40 GstMpegtsJpegXsDescriptor *private_data = pad->prepare_data;
41 GstByteWriter wr;
42 GstBuffer *out_buf = NULL;
43 gsize header_size = 30;
44 guint8 *jxes_header = NULL;
45 GstClockTime seconds = buf->pts / GST_SECOND;
46 GstClockTime minutes = seconds / 60;
47 GstClockTime hours = minutes / 60;
48
49 /* FIXME : Instead of constantly allocating/freeing a new header, we should:
50 * * Generate this header once
51 * * Update it only for the new tcod
52 */
53
54 seconds = seconds % 60;
55 minutes = minutes % 60;
56 hours = hours % 24;
57
58 /* Box is fixed size */
59 gst_byte_writer_init_with_size (&wr, header_size, FALSE);
60
61 gst_byte_writer_put_uint32_be (&wr, header_size);
62 /* Elementary stream header box 'jxes' == 0x6a786573 */
63 gst_byte_writer_put_uint32_be (&wr, 0x6a786573);
64
65 /* brat, frat are 32 bytes */
66 gst_byte_writer_put_uint32_be (&wr, private_data->brat);
67 gst_byte_writer_put_uint32_be (&wr, private_data->frat);
68
69 /* schar, Ppih, Plev */
70 gst_byte_writer_put_uint16_be (&wr, private_data->schar);
71 gst_byte_writer_put_uint16_be (&wr, private_data->Ppih);
72 gst_byte_writer_put_uint16_be (&wr, private_data->Plev);
73
74 gst_byte_writer_put_uint8 (&wr, private_data->colour_primaries);
75 gst_byte_writer_put_uint8 (&wr, private_data->transfer_characteristics);
76 gst_byte_writer_put_uint8 (&wr, private_data->matrix_coefficients);
77
78 gst_byte_writer_put_uint8 (&wr, private_data->video_full_range_flag << 7);
79
80 /* put HHMMSSFF */
81 gst_byte_writer_put_uint8 (&wr, (guint8) hours);
82 gst_byte_writer_put_uint8 (&wr, (guint8) minutes);
83 gst_byte_writer_put_uint8 (&wr, (guint8) seconds);
84 gst_byte_writer_put_uint8 (&wr, 0x0);
85
86 /* Put jxes header in buffer */
87 header_size = gst_byte_writer_get_size (&wr);
88 jxes_header = gst_byte_writer_reset_and_get_data (&wr);
89 out_buf = gst_buffer_new_wrapped (jxes_header, header_size);
90
91 /* Copy complete frame */
92 gst_buffer_copy_into (out_buf, buf,
93 GST_BUFFER_COPY_METADATA | GST_BUFFER_COPY_TIMESTAMPS |
94 GST_BUFFER_COPY_MEMORY, 0, -1);
95 GST_DEBUG_OBJECT (mux, "Prepared JPEGXS PES of size %d",
96 (int) gst_buffer_get_size (out_buf));
97
98 return out_buf;
99 }
100
101 void
102 gst_base_ts_mux_free_jpegxs (gpointer prepare_data)
103 {
104 /* Free prepare data memory object */
105 g_free (prepare_data);
106 }