• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

            路漫漫,長修遠,我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
            數據加載中……

            ffmpeg分析系列之二(文件協議)(轉載)

            (不知原始出處, 方便請告知, 此處轉載于 http://hi.baidu.com/monkeyifox)

            URL協議結構:

            typedef struct URLProtocol {
                const char *name;
                int (*url_open)(URLContext *h, const char *url, int flags);
                int (*url_read)(URLContext *h, unsigned char *buf, int size);
                int (*url_write)(URLContext *h, unsigned char *buf, int size);
                int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
                int (*url_close)(URLContext *h);
                struct URLProtocol *next;
                int (*url_read_pause)(URLContext *h, int pause);
                int64_t (*url_read_seek)(URLContext *h, int stream_index,
                                         int64_t timestamp, int flags);
                int (*url_get_file_handle)(URLContext *h);
            } URLProtocol;



            libavformat/file.c文件的file協議:

            static int file_open(URLContext *h, const char *filename, int flags)
            {
                int access;
                int fd;

                 av_strstart(filename, "file:", &filename);

                if (flags & URL_RDWR) {
                     access = O_CREAT | O_TRUNC | O_RDWR;
                } else if (flags & URL_WRONLY) {
                     access = O_CREAT | O_TRUNC | O_WRONLY;
                } else {
                     access = O_RDONLY;
                }
            #ifdef O_BINARY
                 access |= O_BINARY;
            #endif
                 fd = open(filename, access, 0666);
                if (fd == -1)
                    return AVERROR(errno);
                 h->priv_data = (void *) (intptr_t) fd;
                return 0;
            }

            static int file_read(URLContext *h, unsigned char *buf, int size)
            {
                int fd = (intptr_t) h->priv_data;
                return read(fd, buf, size);
            }

            static int file_write(URLContext *h, unsigned char *buf, int size)
            {
                int fd = (intptr_t) h->priv_data;
                return write(fd, buf, size);
            }

            /* XXX: use llseek */
            static int64_t file_seek(URLContext *h, int64_t pos, int whence)
            {
                int fd = (intptr_t) h->priv_data;
                if (whence == AVSEEK_SIZE) {
                    struct stat st;
                    int ret = fstat(fd, &st);
                    return ret < 0 ? AVERROR(errno) : st.st_size;
                }
                return lseek(fd, pos, whence);
            }

            static int file_close(URLContext *h)
            {
                int fd = (intptr_t) h->priv_data;
                return close(fd);
            }

            static int file_get_handle(URLContext *h)
            {
                return (intptr_t) h->priv_data;
            }

            URLProtocol file_protocol = {
                "file",
                 file_open,
                 file_read,
                 file_write,
                 file_seek,
                 file_close,
                .url_get_file_handle = file_get_handle,
            };


            libavformat/allformats.c文件的av_register_all函數注冊了file協議:

            #define REGISTER_PROTOCOL(X,x) { \
                extern URLProtocol x##_protocol; \
                if(CONFIG_##X##_PROTOCOL) av_register_protocol(&x##_protocol); }


            void av_register_all(void)
            {
                /* 省略部分代碼 */
                /* protocols */
                 REGISTER_PROTOCOL (FILE, file);
                /* 省略部分代碼 */
            }


            把注冊協議函數也貼出來吧:

            URLProtocol *first_protocol = NULL;


            int av_register_protocol(URLProtocol *protocol)
            {
                 URLProtocol **p;
                 p = &first_protocol;
                while (*p != NULL) p = &(*p)->next;
                *p = protocol;
                 protocol->next = NULL;
                return 0;
            }

            posted on 2012-12-14 01:21 Khan 閱讀(1067) 評論(0)  編輯 收藏 引用 所屬分類: GCC/G++跨平臺開發周邊技術

            久久久受www免费人成| 久久97久久97精品免视看秋霞| 九九久久精品国产| 久久精品亚洲男人的天堂| 婷婷国产天堂久久综合五月| 亚洲午夜无码久久久久小说| 色欲综合久久中文字幕网| AV无码久久久久不卡网站下载| 国产叼嘿久久精品久久| 欧美久久一区二区三区| 久久99精品久久久久久久不卡| 国产L精品国产亚洲区久久| 久久亚洲精品无码aⅴ大香| 久久99国产精品久久99果冻传媒| 亚洲?V乱码久久精品蜜桃| 久久久婷婷五月亚洲97号色| 久久亚洲精品无码观看不卡| 色妞色综合久久夜夜| 久久精品国产精品亚洲下载| 99久久99久久精品免费看蜜桃| 久久综合视频网| 久久精品中文字幕一区| 99re这里只有精品热久久| 久久WWW免费人成一看片| 久久综合精品国产一区二区三区| 2022年国产精品久久久久| 久久精品卫校国产小美女| 亚洲人成网站999久久久综合 | 国产亚洲精午夜久久久久久| 亚洲欧美国产精品专区久久 | 国内精品欧美久久精品| 久久水蜜桃亚洲av无码精品麻豆| 久久精品视频一| 久久乐国产综合亚洲精品| 久久综合伊人77777| 99久久国产主播综合精品| 精品久久亚洲中文无码| 99久久国产综合精品网成人影院| 一级做a爰片久久毛片毛片| 久久久青草青青国产亚洲免观| 久久99热这里只有精品国产|