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

            久久精品国产日本波多野结衣| 欧美麻豆久久久久久中文| 久久精品国产99久久久古代| 久久精品国产亚洲av麻豆图片| 久久久久无码精品国产| 色综合色天天久久婷婷基地| 精品久久久久久久国产潘金莲| 亚洲色婷婷综合久久| 99久久亚洲综合精品网站| 人人妻久久人人澡人人爽人人精品| 久久中文骚妇内射| 亚洲欧洲精品成人久久奇米网| 国产午夜福利精品久久2021| 色综合久久久久综合99| 亚洲国产精品久久久久婷婷软件| 亚洲国产精品18久久久久久| 久久夜色精品国产www| 亚洲天堂久久精品| 久久99久久99精品免视看动漫| 中文成人久久久久影院免费观看| 国产一级做a爰片久久毛片| 99久久精品免费看国产一区二区三区| 一本一道久久精品综合| 久久香蕉综合色一综合色88| 久久亚洲AV成人无码电影| 久久精品国产乱子伦| 久久亚洲精品无码aⅴ大香| 久久天天躁狠狠躁夜夜av浪潮 | 老色鬼久久亚洲AV综合| 久久久精品视频免费观看| 国产免费久久久久久无码| 久久精品成人免费网站| 久久国产亚洲高清观看| 久久国产精品无码一区二区三区| 久久久久人妻一区二区三区| 久久久久波多野结衣高潮| 久久成人小视频| 日韩精品久久久久久免费| 久久精品无码一区二区WWW| 伊人色综合久久天天人手人婷 | 久久久亚洲欧洲日产国码aⅴ|