[多媒体] ES格式文件读取

[多媒体] ES格式文件读取,第1张

[多媒体] ES格式文件读取
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 



class EsFileRead
{
public:
    EsFileRead()=default;
    ~EsFileRead();
    bool openFile(const char* uri);
    bool mmapavalable();
    bool readoneframe();
    long findTag_error(long begin);
    long findTag();

    int m_fd;
    char* m_data;
    struct stat m_fileinfo;
    long offset=0;
    long idroffset=-1;
    bool findend=false;
};

EsFileRead::~EsFileRead()
{
    if(-1!=m_fd){
        close(m_fd);
    }
}

bool EsFileRead::mmapavalable()
{
    return true;
}

long EsFileRead::findTag_error(long begin)
{
    if(offset+4 >= m_fileinfo.st_size){
        return m_fileinfo.st_size;
    }

    if(m_data[offset]=='f'){
        if(m_data[offset+1] == 'f'){
            if(m_data[offset+2] == 'f'){
                if(m_data[offset+3] == 'e'){
                    offset+=4;
                    return offset;
                }else{
                    offset+=4;
                    //findTag();
                }
            }else{
                offset+=3;
                //findTag();
            }
        }else{
            offset+=2;
            //findTag();
        }
    }else{
        offset+=1;
        //findTag();
    }
    return -1;
}

long EsFileRead::findTag()
{
    if(offset < 0){
        offset=0;
    }

    if(offset+4 >= m_fileinfo.st_size-1){
        offset = 0;
        return m_fileinfo.st_size-1 + 4;  // +4 is used for compact with   "offset_2 = findTag(offset) - 4;"
    }

    if(m_data[offset]==0x00 && m_data[offset+1]==0x00 && m_data[offset+2]==0x00 && m_data[offset+3]==0x01){
        if(!findend && (m_data[offset+4] == 0x67 || m_data[offset+4] == 0x68 || m_data[offset+4] == 0x65)){
            if(idroffset==-1){
                idroffset = offset;
            }
            offset += 1;
            findTag();
        }else{
            offset += 4;
        }
    }else{
        offset += 1;
        findTag();
    }

    return offset;
}

//bool EsFileRead::readoneframe(long *offset, int* size)
bool EsFileRead::readoneframe()
{
    long offset_1 = 0;
    long offset_2 = 0;
    long offset_tmp = 0;

    findend=false;
    offset_tmp = findTag();
    if(idroffset!=-1){
        offset_1 = idroffset;
    }else{
        offset_1 = offset_tmp - 4;
    }

    findend=true;
    if(offset_1 != m_fileinfo.st_size-1){
        if(idroffset!=-1){
            offset_2 = offset - 4;
        }else{
            offset_2 = findTag() - 4;
        }
        offset -= 4;
    }else{
        offset_2 = m_fileinfo.st_size-1;
    }

    idroffset=-1;
    std::cout << "size : "< 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5716590.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存