HRESULT CASFManager::CreateASFSplitter (IMFByteStream *pContentByteStream,
                                        IMFASFSplitter **ppSplitter)
{
    if (!pContentByteStream || !ppSplitter)
    {
        return E_INVALIDARG;
    }

    if (!m_pContentInfo)
    {
        return MF_E_NOT_INITIALIZED;
    }

    HRESULT hr = S_OK;
    
    IMFASFSplitter *pSplitter = NULL;
    IMFPresentationDescriptor* pPD = NULL;

    UINT64 cbDataOffset = 0, cbDataLength = 0;

    CHECK_HR(hr = MFCreateASFSplitter(&pSplitter));
    
    CHECK_HR(hr = pSplitter->Initialize(m_pContentInfo));

    //Generate the presentation descriptor
    CHECK_HR(hr =  m_pContentInfo->GeneratePresentationDescriptor(&pPD));

    //Get the offset to the start of the Data Object
    CHECK_HR(hr = pPD->GetUINT64(MF_PD_ASF_DATA_START_OFFSET, &cbDataOffset));

    //Get the length of the Data Object
    CHECK_HR(hr = pPD->GetUINT64(MF_PD_ASF_DATA_LENGTH, &cbDataLength));

    m_pByteStream = pContentByteStream;
    m_pByteStream->AddRef();

    m_cbDataOffset = cbDataOffset;
    m_cbDataLength = cbDataLength;

    // Return the pointer to the caller.
    *ppSplitter = pSplitter;
    (*ppSplitter)->AddRef();

    TRACE((L"Created Splitter object.\n"));


done:

    LOG_MSG_IF_FAILED(L"CASFManager::CreateASFSplitter failed.\n", hr);

    SAFE_RELEASE(pSplitter);
    SAFE_RELEASE(pPD);

    return hr;
}
double MediaPlayerPrivateMediaFoundation::durationDouble() const
{
    const double tenMegahertz = 10000000;
    if (!m_mediaSource)
        return 0;

    IMFPresentationDescriptor* descriptor;
    if (!SUCCEEDED(m_mediaSource->CreatePresentationDescriptor(&descriptor)))
        return 0;
    
    UINT64 duration;
    if (!SUCCEEDED(descriptor->GetUINT64(MF_PD_DURATION, &duration)))
        duration = 0;
    descriptor->Release();
    
    return static_cast<double>(duration) / tenMegahertz;
}
Exemplo n.º 3
0
HRESULT CTedPlayer::GetDuration(MFTIME& hnsTime) 
{
    HRESULT hr = S_OK;
    IMFPresentationDescriptor *pPD = NULL;

    if(NULL != m_spSource.p)
    {
        IFC( m_spSource->CreatePresentationDescriptor( &pPD ) );
        IFC( pPD->GetUINT64( MF_PD_DURATION, (UINT64*) &hnsTime ) );
    }
    else
    {
        hr = E_POINTER;
    }

    
Cleanup:
    if(pPD) pPD->Release();
    
    return( hr );
}
HRESULT CASFManager::SetFilePropertiesObject(FILE_PROPERTIES_OBJECT* fileinfo)
{
    if (! m_pContentInfo)
    {
        return MF_E_NOT_INITIALIZED;
    }

    HRESULT hr = S_OK;

    IMFPresentationDescriptor *pPD = NULL;

    UINT32 cbBlobSize = 0;

    CHECK_HR( hr =  m_pContentInfo->GeneratePresentationDescriptor(&pPD));

    //get File ID
    hr = pPD->GetGUID(MF_PD_ASF_FILEPROPERTIES_FILE_ID, &fileinfo->guidFileID);

    // get Creation Time
    hr = pPD->GetBlob(MF_PD_ASF_FILEPROPERTIES_CREATION_TIME, (BYTE *)&fileinfo->ftCreationTime, sizeof(FILETIME), &cbBlobSize);

    //get Data Packets Count
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_PACKETS, &fileinfo->cbPackets);

    //get Play Duration
    hr = pPD->GetUINT64(MF_PD_ASF_FILEPROPERTIES_PLAY_DURATION, &fileinfo->cbPlayDuration);

    //get presentation duration 
    hr = pPD->GetUINT64(MF_PD_DURATION, &fileinfo->cbPresentationDuration);

    //get Send Duration
    hr = pPD->GetUINT64(MF_PD_ASF_FILEPROPERTIES_SEND_DURATION, &fileinfo->cbSendDuration);

    //get preroll
    UINT64 msecspreroll = 0, hnspreroll =0;
    hr = pPD->GetUINT64(MF_PD_ASF_FILEPROPERTIES_PREROLL, &msecspreroll);
    hnspreroll = msecspreroll*10000;
    fileinfo->cbPreroll = hnspreroll;

    //get Flags
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_FLAGS, &fileinfo->cbFlags);

    //get Maximum Data Packet Size
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_MAX_PACKET_SIZE, &fileinfo->cbMaxPacketSize);

    //get Minimum Data Packet Size
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_MIN_PACKET_SIZE, &fileinfo->cbMinPacketSize);
    
    // get Maximum Bit rate
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_MAX_BITRATE, &fileinfo->cbMaxBitRate);
    

    this->m_fileinfo = fileinfo;

    TRACE((L"Read File Properties Object from the ASF Header Object.\n"));

done:

    LOG_MSG_IF_FAILED(L"CASFManager::SetFilePropertiesObject failed.\n", hr);

    SAFE_RELEASE(pPD);

    return hr;

}