这个队列属性(iOS音频队列)是什么意思?

时间:2012-03-19 15:37:52

标签: ios core-audio audioqueue

我想写一个播放音乐的播放器。我看到如下代码:

AudioFileGetPropertyInfo(audioFile,
                         kAudioFilePropertyMagicCookieData, &size, nil);

if (size > 0) {
    cookie = malloc(sizeof(char) * size);
    AudioFileGetProperty(audioFile,
                         kAudioFilePropertyMagicCookieData, &size, cookie);
    AudioQueueSetProperty(aduioQueue,
                          kAudioQueueProperty_MagicCookie, cookie, size);
    free(cookie);
}

我不知道为什么要设置AudioQueueProperty,以及kAudioQueueProperty_MagicCookie的含义是什么?我找不到文档中的帮助。 谁可以指出解决问题的方法。

2 个答案:

答案 0 :(得分:2)

实际上,魔术cookie不仅仅是一个签名,它包含有关编码器的一些信息,最有用的项目是“最大比特率”和“平均比特率”,特别是对于像AudioFileMPEG4Type这样的压缩格式。对于此特定类型,magic cookie与MPEG-4数据文件中的“esds”框相同。您可以在以下位置找到确切的位设置:

http://xhelmboyx.tripod.com/formats/mp4-layout.txt


8+字节。 2 ES描述符框                    =长无符号偏移+长ASCII文本字符串'esds'                     - 如果编码为ISO / IEC 14496-10 AVC标准,则可选择使用:                       =长无符号偏移+长ASCII文本字符串'm4ds'

                -> 4 bytes version/flags = 8-bit hex version + 24-bit hex flags
                    (current = 0)

                -> 1 byte ES descriptor type tag = 8-bit hex value 0x03
                -> 3 bytes extended descriptor type tag string = 3 * 8-bit hex value
                  - types are Start = 0x80 ; End = 0xFE
                  - NOTE: the extended start tags may be left out
                -> 1 byte descriptor type length = 8-bit unsigned length

                  -> 2 bytes ES ID = 16-bit unsigned value
                  -> 1 byte stream priority = 8-bit unsigned value
                    - Defaults to 16 and ranges from 0 through to 31

                    -> 1 byte decoder config descriptor type tag = 8-bit hex value 0x04
                    -> 3 bytes extended descriptor type tag string = 3 * 8-bit hex value
                      - types are Start = 0x80 ; End = 0xFE
                      - NOTE: the extended start tags may be left out
                    -> 1 byte descriptor type length = 8-bit unsigned length

                      -> 1 byte object type ID = 8-bit unsigned value
                        - type IDs are system v1 = 1 ; system v2 = 2
                        - type IDs are MPEG-4 video = 32 ; MPEG-4 AVC SPS = 33
                        - type IDs are MPEG-4 AVC PPS = 34 ; MPEG-4 audio = 64
                        - type IDs are MPEG-2 simple video = 96
                        - type IDs are MPEG-2 main video = 97
                        - type IDs are MPEG-2 SNR video = 98
                        - type IDs are MPEG-2 spatial video = 99
                        - type IDs are MPEG-2 high video = 100
                        - type IDs are MPEG-2 4:2:2 video = 101
                        - type IDs are MPEG-4 ADTS main = 102
                        - type IDs are MPEG-4 ADTS Low Complexity = 103
                        - type IDs are MPEG-4 ADTS Scalable Sampling Rate = 104
                        - type IDs are MPEG-2 ADTS = 105 ; MPEG-1 video = 106
                        - type IDs are MPEG-1 ADTS = 107 ; JPEG video = 108
                        - type IDs are private audio = 192 ; private video = 208
                        - type IDs are 16-bit PCM LE audio = 224 ; vorbis audio = 225
                        - type IDs are dolby v3 (AC3) audio = 226 ; alaw audio = 227
                        - type IDs are mulaw audio = 228 ; G723 ADPCM audio = 229
                        - type IDs are 16-bit PCM Big Endian audio = 230
                        - type IDs are Y'CbCr 4:2:0 (YV12) video = 240 ; H264 video = 241
                        - type IDs are H263 video = 242 ; H261 video = 243
                      -> 6 bits stream type = 3/4 byte hex value
                        - type IDs are object descript. = 1 ; clock ref. = 2
                        - type IDs are scene descript. = 4 ; visual = 4
                        - type IDs are audio = 5 ; MPEG-7 = 6 ; IPMP = 7
                        - type IDs are OCI = 8 ; MPEG Java = 9
                        - type IDs are user private = 32
                      -> 1 bit upstream flag = 1/8 byte hex value
                      -> 1 bit reserved flag = 1/8 byte hex value set to 1
                      -> 3 bytes buffer size = 24-bit unsigned value
                      -> 4 bytes maximum bit rate = 32-bit unsigned value
                      -> 4 bytes average bit rate = 32-bit unsigned value

                        -> 1 byte decoder specific descriptor type tag
                            = 8-bit hex value 0x05
                        -> 3 bytes extended descriptor type tag string
                            = 3 * 8-bit hex value
                          - types are Start = 0x80 ; End = 0xFE
                          - NOTE: the extended start tags may be left out
                        -> 1 byte descriptor type length
                            = 8-bit unsigned length

                          -> ES header start codes = hex dump

                    -> 1 byte SL config descriptor type tag = 8-bit hex value 0x06
                    -> 3 bytes extended descriptor type tag string = 3 * 8-bit hex value
                      - types are Start = 0x80 ; End = 0xFE
                      - NOTE: the extended start tags may be left out
                    -> 1 byte descriptor type length = 8-bit unsigned length

                      -> 1 byte SL value = 8-bit hex value set to 0x02

来自kAudioFilePropertyMagicCookieData的Magic Cookie从ES Descriptor开始(只需忽略地图中描述的前4个字节,其余部分将与magick cookie完全匹配)。

示例魔术cookie将是这样的:

03 80 80 80 22 00 00 00 04 80 80 80 14 40 15 00 18 00 00 00 FA 00 00 00 FA 00 05 80 80 80 02 12 08 06 80 80 80 01 02

最大比特率是偏移18 - > 0XFA00(或64,000) 平均比特率是偏移22-> 0XFA00(或64,000)

虽然根据Apple文档,魔术cookie是可读/写的,但在创建或转换文件之前我没有机会改变比特率。

希望能有所帮助。

答案 1 :(得分:1)

“magic cookie”是一种文件类型签名,由文件开头的唯一字节序列组成,表示文件格式。音频队列框架使用此信息来确定如何从文件流中解码或提取音频信息(而不是使用或信任文件扩展名)。您发布的代码从文件中读取这组字节,并将其作为cookie传递给音频队列。 (例如,将它们解释为PCM样本是错误的。)