yading@11: /* yading@11: * ID3v2 header parser yading@11: * Copyright (c) 2003 Fabrice Bellard yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_ID3V2_H yading@11: #define AVFORMAT_ID3V2_H yading@11: yading@11: #include yading@11: #include "avformat.h" yading@11: #include "internal.h" yading@11: #include "metadata.h" yading@11: yading@11: #define ID3v2_HEADER_SIZE 10 yading@11: yading@11: /** yading@11: * Default magic bytes for ID3v2 header: "ID3" yading@11: */ yading@11: #define ID3v2_DEFAULT_MAGIC "ID3" yading@11: yading@11: #define ID3v2_FLAG_DATALEN 0x0001 yading@11: #define ID3v2_FLAG_UNSYNCH 0x0002 yading@11: #define ID3v2_FLAG_ENCRYPTION 0x0004 yading@11: #define ID3v2_FLAG_COMPRESSION 0x0008 yading@11: yading@11: enum ID3v2Encoding { yading@11: ID3v2_ENCODING_ISO8859 = 0, yading@11: ID3v2_ENCODING_UTF16BOM = 1, yading@11: ID3v2_ENCODING_UTF16BE = 2, yading@11: ID3v2_ENCODING_UTF8 = 3, yading@11: }; yading@11: yading@11: typedef struct ID3v2EncContext { yading@11: int version; ///< ID3v2 minor version, either 3 or 4 yading@11: int64_t size_pos; ///< offset of the tag total size yading@11: int len; ///< size of the tag written so far yading@11: } ID3v2EncContext; yading@11: yading@11: typedef struct ID3v2ExtraMeta { yading@11: const char *tag; yading@11: void *data; yading@11: struct ID3v2ExtraMeta *next; yading@11: } ID3v2ExtraMeta; yading@11: yading@11: typedef struct ID3v2ExtraMetaGEOB { yading@11: uint32_t datasize; yading@11: uint8_t *mime_type; yading@11: uint8_t *file_name; yading@11: uint8_t *description; yading@11: uint8_t *data; yading@11: } ID3v2ExtraMetaGEOB; yading@11: yading@11: typedef struct ID3v2ExtraMetaAPIC { yading@11: AVBufferRef *buf; yading@11: const char *type; yading@11: uint8_t *description; yading@11: enum AVCodecID id; yading@11: } ID3v2ExtraMetaAPIC; yading@11: yading@11: /** yading@11: * Detect ID3v2 Header. yading@11: * @param buf must be ID3v2_HEADER_SIZE byte long yading@11: * @param magic magic bytes to identify the header. yading@11: * If in doubt, use ID3v2_DEFAULT_MAGIC. yading@11: */ yading@11: int ff_id3v2_match(const uint8_t *buf, const char *magic); yading@11: yading@11: /** yading@11: * Get the length of an ID3v2 tag. yading@11: * @param buf must be ID3v2_HEADER_SIZE bytes long and point to the start of an yading@11: * already detected ID3v2 tag yading@11: */ yading@11: int ff_id3v2_tag_len(const uint8_t *buf); yading@11: yading@11: /** yading@11: * Read an ID3v2 tag, including supported extra metadata yading@11: * @param extra_meta If not NULL, extra metadata is parsed into a list of yading@11: * ID3v2ExtraMeta structs and *extra_meta points to the head of the list yading@11: */ yading@11: void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta); yading@11: yading@11: /** yading@11: * Initialize an ID3v2 tag. yading@11: */ yading@11: void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version, yading@11: const char *magic); yading@11: yading@11: /** yading@11: * Convert and write all global metadata from s into an ID3v2 tag. yading@11: */ yading@11: int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3); yading@11: yading@11: /** yading@11: * Write an attached picture from pkt into an ID3v2 tag. yading@11: */ yading@11: int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt); yading@11: yading@11: /** yading@11: * Finalize an opened ID3v2 tag. yading@11: */ yading@11: void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb); yading@11: yading@11: /** yading@11: * Write an ID3v2 tag containing all global metadata from s. yading@11: * @param id3v2_version Subversion of ID3v2; supported values are 3 and 4 yading@11: * @param magic magic bytes to identify the header yading@11: * If in doubt, use ID3v2_DEFAULT_MAGIC. yading@11: */ yading@11: int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, const char *magic); yading@11: yading@11: /** yading@11: * Free memory allocated parsing special (non-text) metadata. yading@11: * @param extra_meta Pointer to a pointer to the head of a ID3v2ExtraMeta list, *extra_meta is set to NULL. yading@11: */ yading@11: void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta); yading@11: yading@11: /** yading@11: * Create a stream for each APIC (attached picture) extracted from the yading@11: * ID3v2 header. yading@11: */ yading@11: int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta); yading@11: yading@11: extern const AVMetadataConv ff_id3v2_34_metadata_conv[]; yading@11: extern const AVMetadataConv ff_id3v2_4_metadata_conv[]; yading@11: yading@11: /** yading@11: * A list of text information frames allowed in both ID3 v2.3 and v2.4 yading@11: * http://www.id3.org/id3v2.4.0-frames yading@11: * http://www.id3.org/id3v2.4.0-changes yading@11: */ yading@11: extern const char ff_id3v2_tags[][4]; yading@11: yading@11: /** yading@11: * ID3v2.4-only text information frames. yading@11: */ yading@11: extern const char ff_id3v2_4_tags[][4]; yading@11: yading@11: /** yading@11: * ID3v2.3-only text information frames. yading@11: */ yading@11: extern const char ff_id3v2_3_tags[][4]; yading@11: yading@11: extern const CodecMime ff_id3v2_mime_tags[]; yading@11: yading@11: extern const char *ff_id3v2_picture_types[21]; yading@11: yading@11: #endif /* AVFORMAT_ID3V2_H */