1 /* ASF muxer plugin for GStreamer 2 * Copyright (C) 2009 Thiago Santos <thiagoss@embedded.ufcg.edu.br> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public 15 * License along with this library; if not, write to the 16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 #ifndef __GST_ASF_OBJECTS_H__ 20 #define __GST_ASF_OBJECTS_H__ 21 22 #include <glib.h> 23 #include <gst/gst.h> 24 #include <gst/base/gstbytereader.h> 25 #include <gst/base/gstcollectpads.h> 26 27 #define ASF_PAYLOAD_IS_KEYFRAME(pay) ((pay->stream_number & 0x80) != 0) 28 #define ASF_MILI_TO_100NANO(v) (v * 10000) 29 #define ASF_GUID_SIZE 16 30 #define ASF_GUID_OBJSIZE_SIZE 24 31 32 typedef struct _Guid 33 { 34 guint32 v1; 35 guint16 v2; 36 guint16 v3; 37 guint64 v4; 38 } Guid; 39 40 typedef struct _GstAsfFileInfo 41 { 42 guint64 packets_count; 43 guint32 packet_size; 44 gboolean broadcast; 45 } GstAsfFileInfo; 46 47 typedef struct _GstAsfPacketInfo 48 { 49 guint8 err_cor_len; 50 gboolean multiple_payloads; 51 guint8 padd_field_type; 52 guint8 packet_field_type; 53 guint8 seq_field_type; 54 55 guint32 packet_size; 56 guint32 padding; 57 guint32 send_time; 58 guint16 duration; 59 gboolean has_keyframe; 60 } GstAsfPacketInfo; 61 62 typedef struct _SimpleIndexEntry 63 { 64 guint32 packet_number; 65 guint16 packet_count; 66 } SimpleIndexEntry; 67 68 typedef struct _AsfPayload 69 { 70 guint8 stream_number; 71 guint8 media_obj_num; 72 guint32 offset_in_media_obj; 73 guint8 replicated_data_length; 74 guint32 media_object_size; 75 guint32 presentation_time; 76 GstBuffer *data; 77 78 GstCollectData *pad; 79 80 /* simple index info */ 81 gboolean has_packet_info; 82 guint32 packet_number; 83 guint16 packet_count; 84 } AsfPayload; 85 86 void gst_asf_generate_file_id (Guid *guid); 87 88 gboolean gst_byte_reader_get_asf_var_size_field (GstByteReader * reader, 89 guint8 field_type, guint32 * var); 90 guint32 gst_asf_read_var_size_field (guint8 * data, guint8 field_type); 91 guint gst_asf_get_var_size_field_len (guint8 field_type); 92 93 GstAsfFileInfo *gst_asf_file_info_new (void); 94 void gst_asf_file_info_reset (GstAsfFileInfo * info); 95 void gst_asf_file_info_free (GstAsfFileInfo * info); 96 97 guint32 gst_asf_payload_get_size (AsfPayload * payload); 98 void gst_asf_payload_free (AsfPayload * payload); 99 100 guint64 gst_asf_get_current_time (void); 101 102 gboolean gst_asf_match_guid (const guint8 * data, const Guid * g); 103 104 void gst_asf_put_i32 (guint8 * buf, gint32 data); 105 void gst_asf_put_time (guint8 * buf, guint64 time); 106 void gst_asf_put_guid (guint8 * buf, Guid guid); 107 void gst_asf_put_payload (guint8 * buf, AsfPayload * payload); 108 guint16 gst_asf_put_subpayload (guint8 * buf, AsfPayload * payload, 109 guint16 size); 110 111 gboolean gst_asf_parse_packet (GstBuffer * buffer, GstAsfPacketInfo * packet, 112 gboolean trust_delta_flag, guint packet_size); 113 gboolean gst_asf_parse_packet_from_data (guint8 * data, gsize size, GstBuffer * buffer, GstAsfPacketInfo * packet, 114 gboolean trust_delta_flag, guint packet_size); 115 guint64 gst_asf_match_and_peek_obj_size (const guint8 * data, 116 const Guid * guid); 117 guint64 gst_asf_match_and_peek_obj_size_buf (GstBuffer * buf, 118 const Guid * guid); 119 gboolean gst_asf_parse_headers (GstBuffer * buffer, GstAsfFileInfo * file_info); 120 gboolean gst_asf_parse_headers_from_data (guint8 * data, guint size, GstAsfFileInfo * file_info); 121 122 /* ASF tags 123 * found at http://msdn.microsoft.com/en-us/library/dd562330(VS.85).aspx 124 */ 125 126 #define ASF_TAG_TITLE "Title\0" 127 #define ASF_TAG_TITLE_SORTNAME "TitleSortOrder\0" 128 129 /* FIXME asf has no artist tag other than AlbumArtist, but it has Author 130 * What to use here? */ 131 #define ASF_TAG_ARTIST "WM/AlbumArtist\0" 132 #define ASF_TAG_ARTIST_SORTNAME "AlbumArtistSortOrder\0" 133 134 #define ASF_TAG_ALBUM_TITLE "WM/AlbumTitle\0" 135 #define ASF_TAG_ALBUM_TITLE_SORTNAME "AlbumTitleSortOrder\0" 136 137 #define ASF_TAG_GENRE "WM/Genre\0" 138 #define ASF_TAG_COMMENT "Comment\0" 139 #define ASF_TAG_TRACK_NUMBER "WM/TrackNumber\0" 140 #define ASF_TAG_COPYRIGHT "Copyright\0" 141 #define ASF_TAG_COMPOSER "WM/Composer\0" 142 143 const gchar *gst_asf_get_asf_tag (const gchar * gsttag); 144 guint gst_asf_get_tag_field_type (GValue * value); 145 gboolean gst_asf_tag_present_in_content_description (const gchar * tag); 146 147 /* ASF Objects Sizes */ 148 #define ASF_HEADER_OBJECT_SIZE 30 149 #define ASF_FILE_PROPERTIES_OBJECT_SIZE 104 150 #define ASF_STREAM_PROPERTIES_OBJECT_SIZE 78 151 #define ASF_HEADER_EXTENSION_OBJECT_SIZE 46 152 #define ASF_AUDIO_SPECIFIC_DATA_SIZE 18 153 #define ASF_VIDEO_SPECIFIC_DATA_SIZE 51 154 #define ASF_DATA_OBJECT_SIZE 50 155 #define ASF_SINGLE_PAYLOAD_HEADER_SIZE 15 156 #define ASF_MULTIPLE_PAYLOAD_HEADER_SIZE 17 157 #define ASF_EXTENDED_STREAM_PROPERTIES_OBJECT_SIZE 88 158 #define ASF_CONTENT_DESCRIPTION_OBJECT_SIZE 34 159 #define ASF_EXT_CONTENT_DESCRIPTION_OBJECT_SIZE 26 160 #define ASF_SIMPLE_INDEX_OBJECT_SIZE 56 161 #define ASF_SIMPLE_INDEX_ENTRY_SIZE 6 162 #define ASF_METADATA_OBJECT_SIZE 26 163 #define ASF_PADDING_OBJECT_SIZE 24 164 165 /* Field types for data object payload description */ 166 #define ASF_FIELD_TYPE_NONE 0 167 #define ASF_FIELD_TYPE_BYTE 1 168 #define ASF_FIELD_TYPE_WORD 2 169 #define ASF_FIELD_TYPE_DWORD 3 170 #define ASF_FIELD_TYPE_MASK 3 171 172 /* tag types */ 173 #define ASF_TAG_TYPE_UNICODE_STR 0 174 #define ASF_TAG_TYPE_BYTES 1 175 #define ASF_TAG_TYPE_BOOL 2 176 #define ASF_TAG_TYPE_DWORD 3 177 #define ASF_TAG_TYPE_QWORD 4 178 #define ASF_TAG_TYPE_WORD 5 179 180 /* GUID objects */ 181 182 #define ASF_HEADER_OBJECT_INDEX 0 183 #define ASF_FILE_PROPERTIES_OBJECT_INDEX 1 184 #define ASF_STREAM_PROPERTIES_OBJECT_INDEX 2 185 #define ASF_AUDIO_MEDIA_INDEX 3 186 #define ASF_NO_ERROR_CORRECTION_INDEX 4 187 #define ASF_AUDIO_SPREAD_INDEX 5 188 #define ASF_HEADER_EXTENSION_OBJECT_INDEX 6 189 #define ASF_RESERVED_1_INDEX 7 190 #define ASF_DATA_OBJECT_INDEX 8 191 #define ASF_EXTENDED_STREAM_PROPERTIES_OBJECT_INDEX 9 192 #define ASF_VIDEO_MEDIA_INDEX 10 193 #define ASF_SIMPLE_INDEX_OBJECT_INDEX 11 194 #define ASF_CONTENT_DESCRIPTION_INDEX 12 195 #define ASF_EXT_CONTENT_DESCRIPTION_INDEX 13 196 #define ASF_METADATA_OBJECT_INDEX 14 197 #define ASF_PADDING_OBJECT_INDEX 15 198 199 extern const Guid guids[]; 200 201 #endif 202