当前位置: 首页>>代码示例>>C++>>正文


C++ DataStream::getPos方法代码示例

本文整理汇总了C++中DataStream::getPos方法的典型用法代码示例。如果您正苦于以下问题:C++ DataStream::getPos方法的具体用法?C++ DataStream::getPos怎么用?C++ DataStream::getPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataStream的用法示例。


在下文中一共展示了DataStream::getPos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: bFoundMatch

/*override*/ Transformation::Result GenericRemover::apply(const Mp3Handler& h, const TransfConfig& transfConfig, const std::string& strOrigSrcName, std::string& strTempName)
{
    const vector<DataStream*>& vpStreams (h.getStreams());
    bool bFoundMatch (false);

    for (int i = 0, n = cSize(vpStreams); i < n; ++i)
    {
        if (matches(vpStreams[i]))
        {
            bFoundMatch = true;
            break;
        }
    }

    if (!bFoundMatch)
    {
        return NOT_CHANGED;
    }

//ttt2 see InnerNonAudioRemover: Lambo has an error in mplayer, because of bit reservoir

    ifstream_utf8 in (h.getName().c_str(), ios::binary);

    { // comp
        switch (transfConfig.getCompAction())
        {
        case TransfConfig::TRANSF_DONT_CREATE: break;
        case TransfConfig::TRANSF_CREATE:
            {
                in.seekg(0);

                for (int i = 0, n = cSize(vpStreams); i < n; ++i)
                {
                    DataStream* p (vpStreams[i]);

                    if (matches(p))
                    {
                        MpegStream* pPrevAudio (i > 0 ? dynamic_cast<MpegStream*>(vpStreams[i - 1]) : 0);
                        MpegStream* pNextAudio (i < n - 1 ? dynamic_cast<MpegStream*>(vpStreams[i + 1]) : 0);

                        string strCompBefore;
                        string strCompAfter;
                        transfConfig.getCompNames(strOrigSrcName, getActionName(), strCompBefore, strCompAfter);

                        streampos posCompBeg (0 != pPrevAudio ? findNearMpegFrameAtLeft(pPrevAudio->getEnd(), in, pPrevAudio) : p->getPos());
                        streampos posCompEnd (0 != pNextAudio ? findNearMpegFrameAtRight(pNextAudio->getPos(), in, pNextAudio) : p->getEnd());

                        { // comp before
                            ofstream_utf8 out (strCompBefore.c_str(), ios::binary);
                            appendFilePart(in, out, posCompBeg, posCompEnd - posCompBeg);
                        }

                        { // comp after
                            if (0 != pPrevAudio || 0 != pNextAudio)
                            {
                                ofstream_utf8 out (strCompAfter.c_str(), ios::binary);
                                appendFilePart(in, out, posCompBeg, p->getPos() - posCompBeg);
                                appendFilePart(in, out, p->getEnd(), posCompEnd - p->getEnd());
                            }
                        }
                    }
                }
            }
            break;

        default: CB_ASSERT (false);
        }
    }

    { // temp
        transfConfig.getTempName(strOrigSrcName, getActionName(), strTempName);
        ofstream_utf8 out (strTempName.c_str(), ios::binary);
        in.seekg(0);

        for (int i = 0, n = cSize(vpStreams); i < n; ++i)
        {
            DataStream* pDataStream (vpStreams[i]);
            if (!matches(pDataStream))
            {
                //qDebug("copying %d for %s", (int)pDataStream->getSize(), pDataStream->getDisplayName());
                pDataStream->copy(in, out);
            }
            /*else
            {
                qDebug("skipping %d for %s", (int)pDataStream->getSize(), pDataStream->getDisplayName());
            }*/
        }
    }

    return CHANGED; // CHANGED_NO_RECALL would be ok in some cases but it's hard to tell when
}
开发者ID:miracle2k,项目名称:mp3diags,代码行数:91,代码来源:StructuralTransformation.cpp

示例2: in

//ttt2 in a way this could take care of Xing headers for CBR streams as well, but it doesn't seem the best place to do it, especially as we ignore most of the data in the Lame header and "restoring a header" means just putting back byte count and frame count
/*override*/ Transformation::Result VbrRepairerBase::repair(const Mp3Handler& h, const TransfConfig& transfConfig, const std::string& strOrigSrcName, std::string& strTempName, bool bForceRebuild)
{
    const vector<DataStream*>& vpStreams (h.getStreams());
    ifstream_utf8 in (h.getName().c_str(), ios::binary);
    set<int> sVbriPos;
    int nAudioPos (-1);
    set<int> sXingPos;
    int n (cSize(vpStreams));
    int nXingPos (-1);
    XingStreamBase* pXingStreamBase (0);
    for (int i = 0; i < n; ++i)
    {
        MpegStream* pAudio (dynamic_cast<MpegStream*>(vpStreams[i]));
        if (0 != pAudio)
        {
            nAudioPos = i;
            break;
        }

        VbriStream* pVbriStream (dynamic_cast<VbriStream*>(vpStreams[i]));
        if (0 != pVbriStream)
        {
            sVbriPos.insert(i);
        }

        XingStreamBase* q (dynamic_cast<XingStreamBase*>(vpStreams[i]));
        if (0 != q)
        {
            sXingPos.insert(i);
            nXingPos = i;
            pXingStreamBase = q;
        }
    }

    if (-1 == nAudioPos) { return NOT_CHANGED; } // no audio
    MpegStream* pAudio (dynamic_cast<MpegStream*>(vpStreams[nAudioPos]));
    if (!pAudio->isVbr()) { return NOT_CHANGED; } // CBR audio

    bool bXingOk (1 == cSize(sXingPos) && 1 == sXingPos.count(nAudioPos - 1) && pXingStreamBase->matches(pAudio));
    if (!bForceRebuild && sVbriPos.empty() && bXingOk) { return NOT_CHANGED; } // exit if there's no VBRI and there's one matching Xing right before the audio


    bool bRepairMp3Fixer (false);
    bool bRemoveXing (true); // if true, existing headers are removed
    bool bAddXing (true); // if true, a header is added before the first Audio

    if (1 == cSize(sXingPos) && nXingPos < n - 2 && pXingStreamBase->isBrokenByMp3Fixer(vpStreams[nXingPos + 1], vpStreams[nXingPos + 2]))
    {
        // ttt2 see also http://www.kde-apps.org/content/show.php/Mp3Fixer?content=31539 for a bug that makes mp3fix.rb write its fix at a wrong address for mono files, but that's not going to be fixed now; at least don't try to fix this on mono files (or better: fix only stereo mpeg1 L III)

        bRemoveXing = bAddXing = false;
        bRepairMp3Fixer = true;
    }

    { // temp
        transfConfig.getTempName(strOrigSrcName, getActionName(), strTempName);
        ofstream_utf8 out (strTempName.c_str(), ios::binary);
        in.seekg(0);

        int i (0);
        for (; i < n; ++i)
        {
            DataStream* p (vpStreams[i]);
            if (0 != dynamic_cast<VbriStream*>(p))
            { // nothing to do; this gets discarded
            }
            else if (0 != dynamic_cast<XingStreamBase*>(p))
            {
                if (bRepairMp3Fixer)
                {
                    XingStreamBase* pXing (dynamic_cast<XingStreamBase*>(p));
                    MpegStream* pAudio (dynamic_cast<MpegStream*>(vpStreams[i + 2]));
                    CB_ASSERT(0 != pXing && 0 != pAudio); // that's what isBrokenByMp3Fixer() is about

                    int nOffs (pXing->getFirstFrame().getSideInfoSize() + MpegFrame::MPEG_FRAME_HDR_SIZE);

                    createXing(out, pXing->getFirstFrame(), pAudio->getFrameCount() + 1, pAudio->getSize() + pXing->getSize());

                    appendFilePart(in, out, p->getPos(), nOffs);
                    streampos pos (p->getPos());

/*#ifdef GENERATE_TOC //!!! Doesn't matter whether GENERATE_TOC is defined or not. Mp3Fixer broke the first audio frame by adding length info and no TOC (although it claims to add TOC as well). What we do here is create a new Xing header (by calling createXing()) and remove the 16 bytes Mp3Fixer added, to restore the first frame to an audio frame, the way it was before Mp3Fixer messed it up. It's up to createXing() to add TOC or not.
                    //const int nXingSize (16 + 100);
#else
                    const int nXingSize (16);
#endif*/

                    const int nMp3FixXingSize (16); // Mp3Fix always adds 16 bytes, because it doesn't use a TOC
                    pos += nMp3FixXingSize + nOffs;
                    appendFilePart(in, out, pos, p->getSize() - nOffs - nMp3FixXingSize);
                }
                else if (!bRemoveXing)
                {
                    p->copy(in, out);
                }
            }
            else if (0 != dynamic_cast<MpegStream*>(p))
            {
                if (bAddXing)
//.........这里部分代码省略.........
开发者ID:miracle2k,项目名称:mp3diags,代码行数:101,代码来源:StructuralTransformation.cpp

示例3: nIndex


//.........这里部分代码省略.........
                {
                    MpegStream* pPrev (m_vpAllStreams.empty() ? 0 : dynamic_cast<MpegStream*>(m_vpAllStreams.back()));
                    m_vpAllStreams.push_back(new TruncatedMpegDataStream(pPrev, nIndex, m_notes, in, posNextFrame - pos));
                    pos += m_vpAllStreams.back()->getSize();
                    ++nIndex;
                    bAdded = true;
                }
                catch (const TruncatedMpegDataStream::NotTruncatedMpegDataStream&)
                {
                    in.clear();
                    in.seekg(pos);
                    /*
                                          ttt2 perhaps add limit of 10 broken streams per file
                                                keep in mind that a transformation that removes broken streams will have trouble processing a file with "10 broken streams", because after it removes the first, a new one will get created, always having 10 of them
                    */

                }
            }

//ttt2 consider this: there's a stream beginning identified at 1000 and the next one is at 8000; if the first begins with a valid MPEG frame and the second is something else, the whole block from 1000 up to 7999 is identified as "broken mpeg"; this isn't quite right: since no other mpeg frame can be found in the block (if it could, it would be the second stream beginning), there's a lot of other data in the stream besides an mpeg frame; this doesn't feel right;

            if (!bAdded)
            {
                streamoff nSize (posNextFrame - pos);
                if (0 != szUnsupportedName)
                {
                    m_vpAllStreams.push_back(new UnsupportedDataStream(nIndex, m_notes, in, nSize, szUnsupportedName, strUnsupportedInfo));
                    //pos += m_vpAllStreams.back()->getSize();
                    ++nIndex;
                }
                else
                {   // either broken or unknown; these have little useful information, so try to append to the previous one, in these cases: both broken and unknown can be appended to truncated and unknown alone can be appended to unknown
                    DataStream* pPrev (m_vpAllStreams.empty() ? 0 : m_vpAllStreams.back());

                    TruncatedMpegDataStream* pPrevTrunc (dynamic_cast<TruncatedMpegDataStream*>(pPrev));
                    UnknownDataStream* pPrevUnkn (dynamic_cast<UnknownDataStream*>(pPrev));
                    UnsupportedDataStream* pPrevUnsupp (dynamic_cast<UnsupportedDataStream*>(pPrev));

                    if (MpegStream::getClassDisplayName() == szBrokenName && 1 == nBrokenMpegFrameCount)
                    {   // a "broken audio" with a single sense doesn't make much sense at this point (but it mattered above, to add a truncated audio stream)
                        szBrokenName = 0;
                    }

                    if (0 != pPrevTrunc && pPrevTrunc->hasSpace(nSize))
                    {   // append to truncated
                        UnknownDataStream* p (new UnknownDataStream(nIndex, m_notes, in, nSize));
                        pPrevTrunc->append(*p);
                        delete p;
                    }
                    else if (0 != szBrokenName)
                    {   // create broken
                        m_vpAllStreams.push_back(new BrokenDataStream(nIndex, m_notes, in, nSize, szBrokenName, strBrokenInfo));
                        //pos += m_vpAllStreams.back()->getSize();
                        ++nIndex;
                    }
                    else if (0 != pPrevUnkn)
                    {   // append to unknown
                        UnknownDataStream* p (new UnknownDataStream(nIndex, m_notes, in, nSize));
                        pPrevUnkn->append(*p);
                        delete p;
                    }
                    else if (0 != pPrevUnsupp)
                    {   // append to unknown
                        UnknownDataStream* p (new UnknownDataStream(nIndex, m_notes, in, nSize));
                        pPrevUnsupp->append(*p);
                        delete p;
                    }
                    else
                    {   // create unknown
                        UnknownDataStream* p (new UnknownDataStream(nIndex, m_notes, in, nSize));
                        m_vpAllStreams.push_back(p);
                        ++nIndex;
                    }
                }

                pos += nSize;
            }
        }
        /*catch (...) // !!! DON'T catch anything; there's no point; the file is changed or something else pretty bad happened, because creating an Unknown stream shouldn't throw; most likely the existing streams became invalid too; also, there's a chance that the implementation of UnknownDataStream has a bug and an infinite loop will be entered, as all the constructors fail and the position in the file doesn't advance
        {
            in.clear();
            in.seekg(pos); not ok
        }*/

    }

    //cout << "=======================\n";

    //CB_ASSERT (!m_vpAllStreams.empty());
    STRM_ASSERT (pos == m_posEnd);
    pos = 0;
    for (int i = 0; i < cSize(m_vpAllStreams); ++i)
    {
        DataStream* p (m_vpAllStreams[i]);
        //cout << p->getInfo() << endl;
        STRM_ASSERT (p->getPos() == pos);
        pos += p->getSize();
    }
    STRM_ASSERT (pos == m_posEnd);
}
开发者ID:wangd,项目名称:mp3diags,代码行数:101,代码来源:Mp3Manip.cpp


注:本文中的DataStream::getPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。