Exemple #1
0
 void ParseSamples(const Indices& samples, Builder& builder) const
 {
   Dbg("Samples: %1% to parse", samples.Count());
   const std::size_t samplesTable = fromLE(Source.SamplesOffset);
   for (Indices::Iterator it = samples.Items(); it; ++it)
   {
     const uint_t samIdx = *it;
     Dbg("Parse sample %1%", samIdx);
     const std::size_t samOffset = ReadWord(samplesTable, samIdx);
     Sample result;
     ParseSample(samOffset, result);
     builder.SetSample(samIdx, result);
   }
 }
Exemple #2
0
HRESULT CHdmvSub::ParseSample(IMediaSample* pSample)
{
    CheckPointer(pSample, E_POINTER);
    HRESULT hr;
    REFERENCE_TIME rtStart = INVALID_TIME, rtStop = INVALID_TIME;
    BYTE* pData = NULL;
    int lSampleLen;

    hr = pSample->GetPointer(&pData);
    if (FAILED(hr) || pData == NULL) {
        return hr;
    }
    lSampleLen = pSample->GetActualDataLength();

    pSample->GetTime(&rtStart, &rtStop);

    return ParseSample(pData, lSampleLen, rtStart, rtStop);
}
Exemple #3
0
void CPGSSubFile::ParseFile(CString fn)
{
    CFile f;
    if (!f.Open(fn, CFile::modeRead | CFile::shareDenyWrite)) {
        return;
    }

    // Header: Sync code | start time | stop time | segment type | segment size
    std::array < BYTE, 2 + 2 * 4 + 1 + 2 > header;
    const int nExtraSize = 1 + 2; // segment type + segment size
    std::vector<BYTE> segBuff;

    while (!m_bStopParsing && f.Read(header.data(), (UINT)header.size()) == header.size()) {
        // Parse the header
        CGolombBuffer headerBuffer(header.data(), (int)header.size());

        if (WORD(headerBuffer.ReadShort()) != PGS_SYNC_CODE) {
            break;
        }

        REFERENCE_TIME rtStart = REFERENCE_TIME(headerBuffer.ReadDword()) * 1000 / 9;
        REFERENCE_TIME rtStop  = REFERENCE_TIME(headerBuffer.ReadDword()) * 1000 / 9;
        headerBuffer.ReadByte(); // segment type
        WORD wLenSegment = (WORD)headerBuffer.ReadShort();

        // Leave some room to add the segment type and size
        int nLenData = nExtraSize + wLenSegment;
        segBuff.resize(nLenData);
        memcpy(segBuff.data(), &header[header.size() - nExtraSize], nExtraSize);

        // Read the segment
        if (wLenSegment && f.Read(&segBuff[nExtraSize], wLenSegment) != wLenSegment) {
            break;
        }

        // Parse the data (even if the segment size is 0 because the header itself is important)
        TRACE_PGSSUB(_T("--------- CPGSSubFile::ParseFile rtStart=%s, rtStop=%s, len=%d ---------\n"),
                     ReftimeToString(rtStart), ReftimeToString(rtStop), nLenData);
        ParseSample(rtStart, rtStop, segBuff.data(), nLenData);
    }
}
Exemple #4
0
HRESULT CPGSSub::ParseSample(IMediaSample* pSample)
{
    CheckPointer(pSample, E_POINTER);

    BYTE* pData = nullptr;
    HRESULT hr = pSample->GetPointer(&pData);
    if (FAILED(hr) || !pData) {
        return hr;
    }
    int lSampleLen = pSample->GetActualDataLength();

    REFERENCE_TIME rtStart = INVALID_TIME, rtStop = INVALID_TIME;
    hr = pSample->GetTime(&rtStart, &rtStop);
    if (FAILED(hr)) {
        return hr;
    }

    TRACE_PGSSUB(_T("--------- CPGSSub::ParseSample rtStart=%s, rtStop=%s, len=%d ---------\n"),
                 ReftimeToString(rtStart + m_rtCurrentSegmentStart), ReftimeToString(rtStop + m_rtCurrentSegmentStart), lSampleLen);

    return ParseSample(rtStart, rtStop, pData, lSampleLen);
}