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

            人妻丰满?V无码久久不卡| 久久久久AV综合网成人| 久久精品不卡| 性高湖久久久久久久久AAAAA| 久久婷婷五月综合色奶水99啪| 狠狠色狠狠色综合久久| 久久成人国产精品二三区| 性做久久久久久久久| 精品免费久久久久久久| 亚洲精品成人网久久久久久| 99久久婷婷国产综合亚洲| 久久久久国产成人精品亚洲午夜| 久久人人爽人人爽人人AV| 久久人人爽人人爽人人片AV麻豆| 国产成人久久精品激情| 久久精品卫校国产小美女| 91精品久久久久久无码| 蜜臀av性久久久久蜜臀aⅴ| 久久无码AV中文出轨人妻| 久久精品国产免费一区| 亚洲精品美女久久久久99| 欧美精品丝袜久久久中文字幕| 国产精品久久一区二区三区| 亚洲成色WWW久久网站| 伊人久久大香线蕉综合网站| 久久av免费天堂小草播放| 99国内精品久久久久久久| 国产精品久久久久久影院| 久久久久99精品成人片试看| 亚洲AV日韩精品久久久久| 久久中文字幕人妻丝袜| 久久久精品久久久久影院| 热久久最新网站获取| 久久亚洲精品无码VA大香大香| 久久人人爽人人澡人人高潮AV| 久久AⅤ人妻少妇嫩草影院| 久久www免费人成精品香蕉| 久久综合色之久久综合| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 亚洲国产精品无码久久久秋霞2 | 久久最近最新中文字幕大全 |