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


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

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


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

示例1: 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

示例2: 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

示例3: pDataStream

/*override*/ Transformation::Result SingleBitRepairer::apply(const Mp3Handler& h, const TransfConfig& transfConfig, const string& strOrigSrcName, string& strTempName)
{
    //CB_ASSERT(UnknownDataStreamBase::BEGIN_SIZE >= x)
    //if (strOrigSrcName in tmp or proc) throw; //ttt2
    const vector<DataStream*>& vpStreams (h.getStreams());
    for (int i = 0, n = cSize(vpStreams); i < n - 2; ++i)
    {
        DataStream* pDataStream (vpStreams[i]);
        MpegStream* pAudio (dynamic_cast<MpegStream*>(pDataStream));
        if (0 != pAudio)
        {
            UnknownDataStreamBase* pFrameToChange (dynamic_cast<UnknownDataStreamBase*>(vpStreams[i + 1]));
            if (0 != pFrameToChange)
            {
                for (int k = 0; k < 32; ++k)
                {
                    try
                    {
                        NoteColl notes (100);

                        char bfr [4];
                        const char* q (pFrameToChange->getBegin());
                        bfr[0] = q[0]; bfr[1] = q[1]; bfr[2] = q[2]; bfr[3] = q[3];
                        bfr[k / 8] ^= 1 << (k % 8);

                        MpegFrameBase frame (notes, pFrameToChange->getPos(), bfr);

                        if (pAudio->isCompatible(frame))
                        {
                            streampos posNewFrameEnd (frame.getPos());
                            posNewFrameEnd += frame.getSize();

                            int j (i + 1);
                            for (; j < n; ++j)
                            {
                                UnknownDataStreamBase* pLastReplacedFrame (dynamic_cast<UnknownDataStreamBase*>(vpStreams[j]));
                                if (0 == pLastReplacedFrame) { break; }
                                streampos posLastReplacedFrameEnd (pLastReplacedFrame->getPos());
                                posLastReplacedFrameEnd += pLastReplacedFrame->getSize();

                                if (posLastReplacedFrameEnd == posNewFrameEnd)
                                {
                                    //qDebug("found");

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

                                    { // comp
                                        switch (transfConfig.getCompAction())
                                        {
                                        case TransfConfig::TRANSF_DONT_CREATE: break;
                                        case TransfConfig::TRANSF_CREATE:
                                            {
                                                streampos posCompBeg (findNearMpegFrameAtLeft(pFrameToChange->getPos(), in, pAudio));

                                                streampos posCompEnd (findNearMpegFrameAtRight(posLastReplacedFrameEnd, in, pAudio));

                                                in.seekg(posCompBeg);

                                                string strCompBefore;
                                                string strCompAfter;
                                                transfConfig.getCompNames(strOrigSrcName, getActionName(), strCompBefore, strCompAfter);
                                                { // tmp before
                                                    ofstream_utf8 out (strCompBefore.c_str(), ios::binary);
                                                    //partialCopy(in, out, 10000);
                                                    //appendFilePart(in, out, pos, 2*nHalfSize);
                                                    appendFilePart(in, out, posCompBeg, posCompEnd - posCompBeg);
                                                }

                                                { // tmp after
                                                    ofstream_utf8 out (strCompAfter.c_str(), ios::binary);
                                                    appendFilePart(in, out, posCompBeg, posCompEnd - posCompBeg);
                                                    out.seekp(pFrameToChange->getPos() - posCompBeg);
                                                    out.write(bfr, 4);
                                                }
                                            }
                                            break;

                                        default: CB_ASSERT (false);
                                        }
                                    }

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

                                        for (int i1 = 0; i1 < n; ++i1)
                                        {
                                            DataStream* q (vpStreams[i1]);
                                            q->copy(in, out);
                                        }

                                        out.seekp(pFrameToChange->getPos());
                                        out.write(bfr, 4);
                                        CB_CHECK1 (out, WriteError());
                                    }

                                    return CHANGED;
                                }
                                if (posLastReplacedFrameEnd > posNewFrameEnd) { break; }
//.........这里部分代码省略.........
开发者ID:miracle2k,项目名称:mp3diags,代码行数:101,代码来源:StructuralTransformation.cpp


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