这个队列属性(iOS Audio Queues)是啥意思?

Posted

技术标签:

【中文标题】这个队列属性(iOS Audio Queues)是啥意思?【英文标题】:What is the meaning of this Queue Property (iOS Audio Queues)?这个队列属性(iOS Audio Queues)是什么意思? 【发布时间】:2012-03-19 15:37:52 【问题描述】:

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

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是什么意思?我无法从文档中找到帮助。 谁能给出解决问题的方向。

【问题讨论】:

【参考方案1】:

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

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


8+ 字节版本。 2 ES 描述符框 = 长无符号偏移 + 长 ASCII 文本字符串 'esds' - 如果编码为 ISO/IEC 14496-10 AVC 标准,则可选择使用: = long unsigned offset + long ASCII text string '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 文档,magic cookie 是读/写的,但我没有机会在创建或转换文件之前更改比特率。

希望对某人有所帮助。

【讨论】:

【参考方案2】:

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

【讨论】:

感谢您的帮助。我找到了关于 kAudioQueueProperty_MagicCookie 的文档。它说:“如果您正在播放或录制的音频格式需要魔术 cookie,则必须在将任何缓冲区排队之前为此属性设置一个值。”......在我的应用程序中,我清除了上面的代码,声音是好的。我的问题是音频队列有能力估计文件格式吗?

以上是关于这个队列属性(iOS Audio Queues)是啥意思?的主要内容,如果未能解决你的问题,请参考以下文章

了解 dispatch_queues 和同步/异步调度

四RabbitMQ中模式—工作队列(Work Queues)模式

Work Queues的轮询分发(工作队列/任务队列)

Dispatch Queues调度队列

RabbitMQ指南之二:工作队列(Work Queues)

RabbitMQ指南之二:工作队列(Work Queues)