• <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
            數(shù)據(jù)加載中……

            ffmpeg分析系列之二(文件協(xié)議)(轉(zhuǎn)載)

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

            URL協(xié)議結(jié)構(gòu):

            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協(xié)議:

            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函數(shù)注冊了file協(xié)議:

            #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);
                /* 省略部分代碼 */
            }


            把注冊協(xié)議函數(shù)也貼出來吧:

            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 閱讀(1060) 評論(0)  編輯 收藏 引用 所屬分類: GCC/G++跨平臺開發(fā)周邊技術(shù)

            久久国产精品久久精品国产| 久久精品极品盛宴观看| 人妻少妇久久中文字幕一区二区| 欧美伊人久久大香线蕉综合| 少妇内射兰兰久久| 久久丝袜精品中文字幕| 亚洲中文字幕无码久久综合网| 精品国产一区二区三区久久久狼| 精品国产福利久久久| 一本综合久久国产二区| 国产精品久久久久久福利69堂| Xx性欧美肥妇精品久久久久久| 久久午夜免费视频| 四虎国产精品免费久久久| 欧美大战日韩91综合一区婷婷久久青草| 中文字幕人妻色偷偷久久| 国产999精品久久久久久| 久久亚洲中文字幕精品有坂深雪 | 久久久久久国产精品无码下载| 一日本道伊人久久综合影| 亚洲狠狠综合久久| 囯产精品久久久久久久久蜜桃 | 久久精品国产99国产精品亚洲| 精品亚洲综合久久中文字幕| 久久99久久99精品免视看动漫| 大美女久久久久久j久久| AV狠狠色丁香婷婷综合久久| 无码任你躁久久久久久老妇| 国产精品久久久久久福利69堂| 久久永久免费人妻精品下载| 久久久久久伊人高潮影院| 热综合一本伊人久久精品 | 狠狠精品干练久久久无码中文字幕| 国产精品99久久免费观看| 亚洲综合日韩久久成人AV| 国产精品久久久久久久久软件| 久久精品国产精品亚洲人人 | 精品久久久久久中文字幕大豆网| 国产AⅤ精品一区二区三区久久| 国产亚洲精午夜久久久久久| 一本久久a久久精品综合夜夜|