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

            怡红院日本一道日本久久 | 日韩AV无码久久一区二区| 婷婷久久综合九色综合九七| 久久久久无码中| 色婷婷综合久久久久中文 | 亚洲欧美一级久久精品| 日韩精品久久久肉伦网站| 久久久久久久综合日本亚洲| 人妻丰满?V无码久久不卡| 精品国产乱码久久久久久呢| 国产精品99久久精品爆乳| 亚洲色大成网站WWW久久九九| 国产激情久久久久影院老熟女免费| 久久精品国产只有精品66| 日日躁夜夜躁狠狠久久AV| 狠狠人妻久久久久久综合蜜桃| 久久这里只有精品久久| 久久国产欧美日韩精品免费| 国产∨亚洲V天堂无码久久久 | 亚洲级αV无码毛片久久精品| 久久国产精品免费一区二区三区| 中文字幕无码久久久| 伊人色综合久久天天| 久久亚洲国产欧洲精品一| 色欲综合久久中文字幕网| 欧美精品福利视频一区二区三区久久久精品 | 久久青青草原亚洲av无码| 精品九九久久国内精品| 91精品国产91久久久久福利| 精品久久久噜噜噜久久久| 久久99热这里只有精品66| 亚洲国产综合久久天堂| 污污内射久久一区二区欧美日韩| 欧美性猛交xxxx免费看久久久 | 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 精品久久人人爽天天玩人人妻| 精品国产一区二区三区久久久狼| 一本一本久久A久久综合精品 | 久久精品成人免费观看97| 国产综合精品久久亚洲| 99久久免费只有精品国产|