Draft: type serialization module
This merge request introduce a module to serialize and de-serialize vlc data types.
It is part of a series of merge requests, which aim to delegate preparse tasks to a dedicated preparse process, mainly for the medialibrary and vlc playqueue use cases.
The preparse process integration will be splitted in four merge requests
- introduce module of serialization/deserialization
- preparse process basis
- implementation of vlc_spawn() for win32 (merged)
- integrate use of preparse process in the medialibrary module and vlc playqueue.
When vlc preparse resources, it generate and set input_item_t
which imply es_format_t
in association with the ressource.
The protocol of communication between vlc process and the preparse process (see !2980 ),
require to serialize resulting objects of the preparse on the preparse process side.
On the vlc side those objects needs to be deserialized.
Merge request reports
Activity
mentioned in merge request !2980
- include/vlc_serializer.h 0 → 100644
1 /***************************************************************************** 2 * vlc_serializer.h The file was not added in the list of includes there: https://code.videolan.org/videolan/vlc/-/blob/cbe01a560827bf49a9767e63c80ae394456d7da9/src/Makefile.am#L24
- include/vlc_serializer.h 0 → 100644
40 */ 41 typedef struct type_serializer_t 42 { 43 struct vlc_object_t obj; 44 45 void *type; 46 47 int ( * pf_serialize )( struct type_serializer_t * ); 48 int ( * pf_deserialize )( struct type_serializer_t * ); 49 50 /* serialization */ 51 struct vlc_memstream *serialized_type; 52 53 /* deserialization */ 54 char *serialized; 55 unsigned int buffer_size; - modules/misc/serializers/serialize.c 0 → 100644
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 19 *****************************************************************************/ 20 21 #ifdef HAVE_CONFIG_H 22 # include "config.h" 23 #endif 24 25 #include <vlc_common.h> 26 #include <vlc_plugin.h> 27 28 vlc_module_begin() changed milestone to %4.0
Why use modules over fixed functions in libvlc/libvlccore/libvlcserialize? I'ts not like you're going to have several modules with the same capability.
Edited by Denis Charmet- modules/misc/serializers/es_format.c 0 → 100644
27 #include <vlc_memstream.h> 28 #include <vlc_es.h> 29 30 /***************************************************************************** 31 * Local prototypes 32 *****************************************************************************/ 33 int serialize_es_format(type_serializer_t *serializer); 34 int deserialize_es_format(type_serializer_t *serializer); 35 36 int serialize_es_format(type_serializer_t *serializer) 37 { 38 es_format_t *es = (es_format_t *)serializer->type; 39 struct vlc_memstream *serialized_format = serializer->serialized_type; 40 41 vlc_memstream_write(serialized_format, &es->i_cat, sizeof(es->i_cat)); 42 vlc_memstream_write(serialized_format, &es->i_codec, sizeof(es->i_codec)); NIT: As a rule of thumb, when you serialize, you should stick to fixed and known size containers or send their size too. Here it works because it's planned to be used in the same machine but if we start imagining process running on different machines you'd have to take different size and endianness into account.
- include/vlc_serializer.h 0 → 100644
26 /** 27 * Structure received by serializer/deserializer modules. 28 * 29 * The caller has to fill the structure following: 30 * - serialization: 31 * 1. type to serialize. 32 * 2. valid vlc_memstream, which will be filled with type content as raw bytes 33 * by the serializer. 34 * 35 * - deserialization: 36 * 1. type which will initialized from the content of the raw type buffer by 37 * the deserializer. 38 * 2. buffer of the type serialized. 39 * 3. buffer size 40 */ 41 typedef struct type_serializer_t - include/vlc_serializer.h 0 → 100644
33 * by the serializer. 34 * 35 * - deserialization: 36 * 1. type which will initialized from the content of the raw type buffer by 37 * the deserializer. 38 * 2. buffer of the type serialized. 39 * 3. buffer size 40 */ 41 typedef struct type_serializer_t 42 { 43 struct vlc_object_t obj; 44 45 void *type; 46 47 int ( * pf_serialize )( struct type_serializer_t * ); 48 int ( * pf_deserialize )( struct type_serializer_t * ); - include/vlc_serializer.h 0 → 100644
38 * 2. buffer of the type serialized. 39 * 3. buffer size 40 */ 41 typedef struct type_serializer_t 42 { 43 struct vlc_object_t obj; 44 45 void *type; 46 47 int ( * pf_serialize )( struct type_serializer_t * ); 48 int ( * pf_deserialize )( struct type_serializer_t * ); 49 50 /* serialization */ 51 struct vlc_memstream *serialized_type; 52 53 /* deserialization */ - include/vlc_serializer.h 0 → 100644
30 * - serialization: 31 * 1. type to serialize. 32 * 2. valid vlc_memstream, which will be filled with type content as raw bytes 33 * by the serializer. 34 * 35 * - deserialization: 36 * 1. type which will initialized from the content of the raw type buffer by 37 * the deserializer. 38 * 2. buffer of the type serialized. 39 * 3. buffer size 40 */ 41 typedef struct type_serializer_t 42 { 43 struct vlc_object_t obj; 44 45 void *type; - modules/misc/serializers/es_format.c 0 → 100644
111 vlc_memstream_write(serialized_format, es->p_extra, es->i_extra); 112 113 return VLC_SUCCESS; 114 } 115 116 #define BOUNDARY_CHECK(offset) \ 117 do { \ 118 if (cur_pos + offset >= (serialized_format + size)) \ 119 goto error; \ 120 } while (0); 121 122 int deserialize_es_format(type_serializer_t *serializer) 123 { 124 const char *serialized_format = serializer->serialized; 125 const char *cur_pos = serialized_format; 126 es_format_t *es = (es_format_t *)serializer->type; mentioned in merge request !6024