• <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

            路漫漫,長(zhǎng)修遠(yuǎn),我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評(píng)論 - 257, 引用 - 0
            數(shù)據(jù)加載中……

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

            (不知原始出處, 方便請(qǐng)告知, 此處轉(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ù)注冊(cè)了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);
                /* 省略部分代碼 */
            }


            把注冊(cè)協(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 閱讀(1067) 評(píng)論(0)  編輯 收藏 引用 所屬分類: GCC/G++跨平臺(tái)開發(fā)周邊技術(shù)

            国产高潮国产高潮久久久91 | 中文字幕亚洲综合久久| 国产精品欧美久久久天天影视| 伊人久久精品线影院| 亚洲中文字幕无码久久2017| 久久精品国产精品亚洲精品| 日本高清无卡码一区二区久久| 久久精品国产亚洲AV麻豆网站| 99久久伊人精品综合观看| 国产精品一区二区久久精品涩爱| 亚洲天堂久久久| 青青国产成人久久91网| 亚洲精品无码久久久久去q| 久久婷婷五月综合色奶水99啪| 久久人人爽人人精品视频| 国产成人精品久久| 久久AAAA片一区二区| 久久久综合九色合综国产| 99蜜桃臀久久久欧美精品网站| 国产99久久久国产精品~~牛| 精品久久久无码人妻中文字幕| 久久久久亚洲爆乳少妇无| 99久久久国产精品免费无卡顿 | 国产精品久久久久一区二区三区| 亚洲精品乱码久久久久久蜜桃图片 | 国产高潮国产高潮久久久| 久久精品国产99国产精品亚洲| 国产精品99久久久久久董美香| 狠狠色丁香婷婷综合久久来| 无码人妻少妇久久中文字幕蜜桃| 久久亚洲日韩看片无码| 精品国产乱码久久久久久人妻 | 国产99久久九九精品无码| 久久这里只有精品久久| 国产韩国精品一区二区三区久久| 亚洲国产美女精品久久久久∴| 亚洲综合熟女久久久30p| 久久综合九色综合网站| 国内精品人妻无码久久久影院| 久久久久久毛片免费播放| 国产人久久人人人人爽 |