0

音楽を再生するプレーヤーを書きたいと思います。以下のようなコードが表示されます。

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 についての手段は何ですか? ドキュメントからヘルプが見つかりません。問題を解決するための指示を与えることができる人。

4

2 に答える 2

2

実際には、マジック クッキーは単なる署名ではなく、エンコーダに関する情報を保持します。特に AudioFileMPEG4Type のような圧縮形式の場合、最も役立つ項目は「最大ビット レート」と「平均ビット レート」です。この特定のタイプのマジック クッキーは、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 と完全に一致します)。

サンプルのマジック クッキーは次のようになります。

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 のドキュメントによると、マジック クッキーは読み書き可能ですが、ファイルを作成または変換する前にビット レートを変更する機会はありませんでした。

それが誰かを助けることを願っています。

于 2013-10-11T03:41:05.020 に答える
1

「マジック クッキー」は、ファイル形式を示す、ファイルの先頭にある一意のバイト シーケンスで構成されるファイル タイプ シグネチャです。Audio Queue フレームワークは、この情報を使用して、(ファイル名拡張子を使用または信頼する代わりに) ファイル ストリームからオーディオ情報をデコードまたは抽出する方法を決定します。投稿したコードは、ファイルからこの一連のバイトを読み取り、それを Cookie としてオーディオ キューに渡します。(たとえば、代わりに PCM サンプルとして解釈させるのは間違いです)。

于 2012-03-19T16:43:01.423 に答える