From 067185e7daf4f294e815d968aa7f7c87cf6b2aae Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 12 May 2022 13:19:58 +1000 Subject: [PATCH] closedcaption: move cdp framerate table to common file shared by both cccombiner and ccconverter Part-of: --- .../ext/closedcaption/ccutils.c | 59 +++++++++++++++++++ .../ext/closedcaption/ccutils.h | 46 +++++++++++++++ .../ext/closedcaption/gstcccombiner.c | 25 +------- .../ext/closedcaption/gstcccombiner.h | 9 --- .../ext/closedcaption/gstccconverter.c | 44 +------------- .../ext/closedcaption/meson.build | 2 +- 6 files changed, 108 insertions(+), 77 deletions(-) create mode 100644 subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c create mode 100644 subprojects/gst-plugins-bad/ext/closedcaption/ccutils.h diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c b/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c new file mode 100644 index 0000000000..3c967540f0 --- /dev/null +++ b/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.c @@ -0,0 +1,59 @@ +/* + * GStreamer + * Copyright (C) 2022 Matthew Waters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "ccutils.h" + +static const struct cdp_fps_entry cdp_fps_table[] = { + {0x1f, 24000, 1001, 25, 22, 3 /* FIXME: alternating max cea608 count! */ }, + {0x2f, 24, 1, 25, 22, 2}, + {0x3f, 25, 1, 24, 22, 2}, + {0x4f, 30000, 1001, 20, 18, 2}, + {0x5f, 30, 1, 20, 18, 2}, + {0x6f, 50, 1, 12, 11, 1}, + {0x7f, 60000, 1001, 10, 9, 1}, + {0x8f, 60, 1, 10, 9, 1}, +}; +const struct cdp_fps_entry null_fps_entry = { 0, 0, 0, 0 }; + +const struct cdp_fps_entry * +cdp_fps_entry_from_fps (guint fps_n, guint fps_d) +{ + int i; + for (i = 0; i < G_N_ELEMENTS (cdp_fps_table); i++) { + if (cdp_fps_table[i].fps_n == fps_n && cdp_fps_table[i].fps_d == fps_d) + return &cdp_fps_table[i]; + } + return &null_fps_entry; +} + +const struct cdp_fps_entry * +cdp_fps_entry_from_id (guint8 id) +{ + int i; + for (i = 0; i < G_N_ELEMENTS (cdp_fps_table); i++) { + if (cdp_fps_table[i].fps_idx == id) + return &cdp_fps_table[i]; + } + return &null_fps_entry; +} diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.h b/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.h new file mode 100644 index 0000000000..d7586c8346 --- /dev/null +++ b/subprojects/gst-plugins-bad/ext/closedcaption/ccutils.h @@ -0,0 +1,46 @@ +/* + * GStreamer + * Copyright (C) 2022 Matthew Waters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include + +#ifndef __CCUTILS_H__ +#define __CCUTILS_H__ + +G_BEGIN_DECLS + +struct cdp_fps_entry +{ + guint8 fps_idx; /* value stored in cdp */ + guint fps_n, fps_d; + guint max_cc_count; + guint max_ccp_count; + guint max_cea608_count; +}; + +G_GNUC_INTERNAL +const struct cdp_fps_entry * cdp_fps_entry_from_fps (guint fps_n, guint fps_d); +G_GNUC_INTERNAL +const struct cdp_fps_entry * cdp_fps_entry_from_id (guint8 id); + +extern const struct cdp_fps_entry null_fps_entry; + +G_END_DECLS + +#endif diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.c b/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.c index 15a41c1c97..0f7517041f 100644 --- a/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.c +++ b/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.c @@ -28,6 +28,7 @@ #include #include +#include "ccutils.h" #include "gstcccombiner.h" GST_DEBUG_CATEGORY_STATIC (gst_cc_combiner_debug); @@ -192,30 +193,6 @@ done: #define MAX_CDP_PACKET_LEN 256 #define MAX_CEA608_LEN 32 -static const struct cdp_fps_entry cdp_fps_table[] = { - {0x1f, 24000, 1001, 25, 22, 3 /* FIXME: alternating max cea608 count! */ }, - {0x2f, 24, 1, 25, 22, 2}, - {0x3f, 25, 1, 24, 22, 2}, - {0x4f, 30000, 1001, 20, 18, 2}, - {0x5f, 30, 1, 20, 18, 2}, - {0x6f, 50, 1, 12, 11, 1}, - {0x7f, 60000, 1001, 10, 9, 1}, - {0x8f, 60, 1, 10, 9, 1}, -}; -static const struct cdp_fps_entry null_fps_entry = { 0, 0, 0, 0 }; - -static const struct cdp_fps_entry * -cdp_fps_entry_from_fps (guint fps_n, guint fps_d) -{ - int i; - for (i = 0; i < G_N_ELEMENTS (cdp_fps_table); i++) { - if (cdp_fps_table[i].fps_n == fps_n && cdp_fps_table[i].fps_d == fps_d) - return &cdp_fps_table[i]; - } - return &null_fps_entry; -} - - static GstBuffer * make_cdp (GstCCCombiner * self, const guint8 * cc_data, guint cc_data_len, const struct cdp_fps_entry *fps_entry, const GstVideoTimeCode * tc) diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.h b/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.h index 6336ab1b1e..2b17e41601 100644 --- a/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.h +++ b/subprojects/gst-plugins-bad/ext/closedcaption/gstcccombiner.h @@ -40,15 +40,6 @@ G_BEGIN_DECLS typedef struct _GstCCCombiner GstCCCombiner; typedef struct _GstCCCombinerClass GstCCCombinerClass; -struct cdp_fps_entry -{ - guint8 fps_idx; - guint fps_n, fps_d; - guint max_cc_count; - guint max_ccp_count; - guint max_cea608_count; -}; - struct _GstCCCombiner { GstAggregator parent; diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/gstccconverter.c b/subprojects/gst-plugins-bad/ext/closedcaption/gstccconverter.c index 1774364eb7..10d12044ee 100644 --- a/subprojects/gst-plugins-bad/ext/closedcaption/gstccconverter.c +++ b/subprojects/gst-plugins-bad/ext/closedcaption/gstccconverter.c @@ -28,6 +28,7 @@ #include #include +#include "ccutils.h" #include "gstccconverter.h" GST_DEBUG_CATEGORY_STATIC (gst_cc_converter_debug); @@ -471,49 +472,6 @@ invalid_caps: } } -struct cdp_fps_entry -{ - guint8 fps_idx; - guint fps_n, fps_d; - guint max_cc_count; - guint max_ccp_count; - guint max_cea608_count; -}; - -static const struct cdp_fps_entry cdp_fps_table[] = { - {0x1f, 24000, 1001, 25, 22, 3 /* FIXME: alternating max cea608 count! */ }, - {0x2f, 24, 1, 25, 22, 2}, - {0x3f, 25, 1, 24, 22, 2}, - {0x4f, 30000, 1001, 20, 18, 2}, - {0x5f, 30, 1, 20, 18, 2}, - {0x6f, 50, 1, 12, 11, 1}, - {0x7f, 60000, 1001, 10, 9, 1}, - {0x8f, 60, 1, 10, 9, 1}, -}; -static const struct cdp_fps_entry null_fps_entry = { 0, 0, 0, 0 }; - -static const struct cdp_fps_entry * -cdp_fps_entry_from_id (guint8 id) -{ - int i; - for (i = 0; i < G_N_ELEMENTS (cdp_fps_table); i++) { - if (cdp_fps_table[i].fps_idx == id) - return &cdp_fps_table[i]; - } - return &null_fps_entry; -} - -static const struct cdp_fps_entry * -cdp_fps_entry_from_fps (guint fps_n, guint fps_d) -{ - int i; - for (i = 0; i < G_N_ELEMENTS (cdp_fps_table); i++) { - if (cdp_fps_table[i].fps_n == fps_n && cdp_fps_table[i].fps_d == fps_d) - return &cdp_fps_table[i]; - } - return &null_fps_entry; -} - static void get_framerate_output_scale (GstCCConverter * self, const struct cdp_fps_entry *in_fps_entry, gint * scale_n, gint * scale_d) diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/meson.build b/subprojects/gst-plugins-bad/ext/closedcaption/meson.build index 568d51fa55..ab8358254c 100644 --- a/subprojects/gst-plugins-bad/ext/closedcaption/meson.build +++ b/subprojects/gst-plugins-bad/ext/closedcaption/meson.build @@ -12,7 +12,7 @@ zvbi_sources = [ if closedcaption_dep.found() gstclosedcaption = library('gstclosedcaption', 'gstcccombiner.c', 'gstccextractor.c', 'gstccconverter.c', 'gstclosedcaption.c', - 'gstline21dec.c', 'gstcea708decoder.c', 'gstceaccoverlay.c', 'gstline21enc.c', + 'gstline21dec.c', 'gstcea708decoder.c', 'gstceaccoverlay.c', 'gstline21enc.c', 'ccutils.c', zvbi_sources, c_args : gst_plugins_bad_args, link_args : noseh_link_args,