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

            国内精品九九久久精品| 久久se精品一区精品二区| 精品久久久久久无码人妻蜜桃| 久久精品亚洲一区二区三区浴池 | 久久婷婷综合中文字幕| 精品久久久久久无码中文野结衣 | 亚洲精品国产美女久久久| 久久精品国产第一区二区三区| 精品国产乱码久久久久久1区2区 | 东方aⅴ免费观看久久av| 人妻少妇久久中文字幕一区二区 | 久久久噜噜噜www成人网| 麻豆精品久久精品色综合| 午夜视频久久久久一区| av午夜福利一片免费看久久| 久久99热这里只有精品国产| 久久综合狠狠综合久久| 性做久久久久久免费观看| 久久99国内精品自在现线| 久久人人爽人爽人人爽av| 奇米综合四色77777久久| 久久露脸国产精品| 国产精品久久永久免费| 久久天天躁夜夜躁狠狠| 国产精品丝袜久久久久久不卡| 久久精品国产亚洲AV大全| 97精品依人久久久大香线蕉97| 久久精品国产一区二区三区| 99久久久精品| 久久国产色AV免费观看| 伊人久久久AV老熟妇色| 女人高潮久久久叫人喷水| 久久婷婷人人澡人人| 国产福利电影一区二区三区久久久久成人精品综合 | 久久精品国产亚洲AV大全| 日韩精品久久久肉伦网站| 2021最新久久久视精品爱| 欧美午夜A∨大片久久| 婷婷久久综合| 亚洲国产香蕉人人爽成AV片久久| 伊人色综合久久天天|