[prev in list] [next in list] [prev in thread] [next in thread]
List: helix-datatype-cvs
Subject: [Datatype-cvs]
From: yuanzhang () helixcommunity ! org
Date: 2011-08-24 3:44:28
Message-ID: 201108240344.p7O3ipaK011520 () mailer ! progressive-comp ! com
[Download RAW message or body]
Update of /cvsroot/datatype/flash/flv/fileformat
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv2297
Added Files:
Tag: hxclient_3_6_1_atlas
flv_interleave_payload.cpp
Log Message:
Overview:
Flv file format of 361 branch does not have important update, which existed on head branch.
Add 6 files which only exit on head branch into 361 branch.
no configuration files is changed, release packet will be not impacted.
--- NEW FILE: flv_interleave_payload.cpp ---
/* ***** BEGIN LICENSE BLOCK *****
*
* Portions Copyright (c) 1995-2006 RealNetworks, Inc. All Rights Reserved.
*
* Patent Notices: This file may contain technology protected by one or
* more of the patents listed at www.helixcommunity.org
*
* 1. The contents of this file, and the files included with this file,
* are protected by copyright controlled by RealNetworks and its
* licensors, and made available by RealNetworks subject to the current
* version of the RealNetworks Public Source License (the "RPSL")
* available at * http://www.helixcommunity.org/content/rpsl unless
* you have licensed the file under the current version of the
* RealNetworks Community Source License (the "RCSL") available at
* http://www.helixcommunity.org/content/rcsl, in which case the RCSL
* will apply. You may also obtain the license terms directly from
* RealNetworks. You may not use this file except in compliance with
* the RPSL or, if you have a valid RCSL with RealNetworks applicable
* to this file, the RCSL. Please see the applicable RPSL or RCSL for
* the rights, obligations and limitations governing use of the
* contents of the file.
*
* 2. Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 (the
* "GPL") in which case the provisions of the GPL are applicable
* instead of those above. Please note that RealNetworks and its
* licensors disclaim any implied patent license under the GPL.
* If you wish to allow use of your version of this file only under
* the terms of the GPL, and not to allow others
* to use your version of this file under the terms of either the RPSL
* or RCSL, indicate your decision by deleting Paragraph 1 above
* and replace them with the notice and other provisions required by
* the GPL. If you do not delete Paragraph 1 above, a recipient may
* use your version of this file under the terms of any one of the
* RPSL, the RCSL or the GPL.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the
* portions it created. Copying, including reproducing, storing,
* adapting or translating, any or all of this material other than
* pursuant to the license terms referred to above requires the prior
* written consent of RealNetworks and its licensors
*
* This file, and the files included with this file, is distributed
* and made available by RealNetworks on an 'AS IS' basis, WITHOUT
* WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS
* AND ITS LICENSORS HEREBY DISCLAIM ALL SUCH WARRANTIES, INCLUDING
* WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
#include "hxtypes.h"
#include "hxcom.h"
#include "hxfiles.h"
#include "ihxpckts.h"
#include "pckunpck.h"
#include "hxtlogutil.h"
#include "flvparse.h"
#include "flv_file_format.h"
#include "flv_interleave_payload.h"
#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif
CInterleavedPayload::CInterleavedPayload(IUnknown* pContext,
CHXFLVFileFormat* pFF)
: CFLVPayload(pContext, pFF)
, m_ulLastInterleavedTimeStamp(0)
{
}
CInterleavedPayload::~CInterleavedPayload()
{
}
UINT32
CInterleavedPayload::InitStreams(const CHXFLVHeader& flvHeader)
{
m_ulStreamCount = 1;
m_usAudioStreamNum = 0;
m_usVideoStreamNum = 0;
return m_ulStreamCount;
}
HX_RESULT
CInterleavedPayload::PrepareStreamHeader(UINT16 usStreamNum, REF(IHXValues*) rpHdr)
{
HX_RESULT retVal = HXR_UNEXPECTED;
if (m_ulStreamCount == 1 && m_pContext && usStreamNum == 0)
{
retVal = m_pFF->PrepareVideoStreamHeader(0, rpHdr);
if (SUCCEEDED(retVal))
{
// Set the "ASMRuleBook" property
SetCStringPropertyCCF(rpHdr, "ASMRuleBook", "Marker=0;Marker=1;", m_pContext);
// Set the "MimeType" property
SetCStringPropertyCCF(rpHdr, "MimeType", HX_FLV_INTERLEAVED_STREAM_MIME_TYPE, m_pContext);
}
}
return retVal;
}
HX_RESULT
CInterleavedPayload::OnVideoPacket(const CHXFLVTagHeader& tagHeader,
const CHXFLVVideoTagHeader& videoHeader,
IHXBuffer* pBuffer,
REF(IHXPacket*) pPacket /* OUT */,
REF(UINT16) usStreamNum /* OUT */)
{
// always full sample (switch_off)
BYTE ucASMFlags = HX_ASM_SWITCH_OFF;
// interleaved stream can switch_on at video keyframes only
if (videoHeader.GetFrameType() == HX_FLV_VIDEO_FRAME_TYPE_KEYFRAME)
{
ucASMFlags |= HX_ASM_SWITCH_ON;
}
return CreatePacket(tagHeader, pBuffer, ucASMFlags, pPacket);
}
HX_RESULT
CInterleavedPayload::OnAudioPacket(const CHXFLVTagHeader& tagHeader,
const CHXFLVAudioTagHeader& audioHeader,
IHXBuffer* pBuffer,
REF(IHXPacket*) pPacket /* OUT */,
REF(UINT16) usStreamNum /* OUT */)
{
// always full sample (switch_off)
// interleaved stream can switch_on at video keyframes only,
// so never switch_on
return CreatePacket(tagHeader, pBuffer, HX_ASM_SWITCH_OFF, pPacket);
}
HX_RESULT
CInterleavedPayload::OnScriptPacket(const CHXFLVTagHeader& tagHeader,
IHXBuffer* pBuffer,
REF(IHXPacket*) pPacket /* OUT */,
REF(UINT16) usStreamNum /* OUT */)
{
// always full sample (switch_off)
// interleaved stream can switch_on at video keyframes only,
// so never switch_on
return CreatePacket(tagHeader, pBuffer, HX_ASM_SWITCH_OFF, pPacket);
}
HX_RESULT
CInterleavedPayload::CreatePacket(const CHXFLVTagHeader& tagHeader,
IHXBuffer* pBuffer,
BYTE ucASMFlags,
REF(IHXPacket*) pPacket /* OUT */)
{
HX_RESULT retVal = HXR_OK;
IHXBuffer* pPktBuffer = NULL;
UINT16 usStreamNum = 0;
UINT16 usRuleNum = 1;
retVal = CreatePacketCCF(pPacket, m_pContext);
// Create the buffer for the interleaved packet
if (SUCCEEDED(retVal))
{
retVal = CreateInterleavedBuffer(pBuffer, pPktBuffer);
}
if (SUCCEEDED(retVal))
{
// Get the timestamp
UINT32 ulInterleavedTimeStamp = tagHeader.GetTimeStamp();
// Make sure this timestamp is at least as great as the
// last interleaved timestamp. Some apps (like RealPlayer)
// will append application-specific FLV tags onto the
// end of the file and will assign an arbitrary timestamp
// of 0 to these FLV tags. We don't want to send an
// out-of-timestamp order packet.
if (ulInterleavedTimeStamp < m_ulLastInterleavedTimeStamp)
{
ulInterleavedTimeStamp = m_ulLastInterleavedTimeStamp;
}
// Set the packet values
// Everything is on stream 0!
// Always marker bit on (rule 1)
retVal = pPacket->Set(pPktBuffer, ulInterleavedTimeStamp,
0, ucASMFlags, 1);
// Save the last interleaved timestamp
m_ulLastInterleavedTimeStamp = ulInterleavedTimeStamp;
}
HX_RELEASE(pPktBuffer);
return retVal;
}
HX_RESULT
CInterleavedPayload::CreateInterleavedBuffer(IHXBuffer* pBufferIn,
REF(IHXBuffer*) rpBufferOut,
HXBOOL bUseTagHdr)
{
HX_RESULT retVal = HXR_UNEXPECTED;
HX_ASSERT(rpBufferOut == NULL);
if (m_pContext && pBufferIn && m_pFF->m_pFLVTagHeader && m_pFF->m_pFLVHeader)
{
// Compute the file offset
UINT32 ulFileOffset = m_pFF->m_ulFileOffset - pBufferIn->GetSize();
if (bUseTagHdr)
{
ulFileOffset -= m_pFF->m_pFLVTagHeader->GetSize();
}
// Determine if this is the first packet in the FLV file. If so,
// then we will attach the FLV header to the packet payload
HXBOOL bFirstInterleavedPacket = FALSE;
if (ulFileOffset == m_pFF->m_cHeader.GetDataOffset())
{
bFirstInterleavedPacket = TRUE;
}
// Compute the size of the interleaved buffer
UINT32 ulSize = 4 + // file offset
pBufferIn->GetSize(); // FLV data size - 1 byte
if (bUseTagHdr)
{
ulSize += m_pFF->m_pFLVTagHeader->GetSize(); // FLV tag size + 1 byte
}
if (bFirstInterleavedPacket)
{
ulSize += m_pFF->m_pFLVHeader->GetSize();
}
// Create a buffer of this size
retVal = CreateSizedBufferCCF(rpBufferOut, m_pContext, ulSize);
if (SUCCEEDED(retVal))
{
// Get the buffer pointer
BYTE* pBuf = rpBufferOut->GetBuffer();
UINT32 ulLen = rpBufferOut->GetSize();
// If we are sending the first interleaved packet, then
// we also send the FLV header at the beginning, so the
// file offset is always 0 in this case.
if (bFirstInterleavedPacket)
{
ulFileOffset = 0;
}
// Pack the file offset
PackUINT32BEInc(&pBuf, &ulLen, ulFileOffset);
// Are we sending the first interleaved packet?
if (bFirstInterleavedPacket)
{
// Copy the FLV header
memcpy(pBuf, m_pFF->m_pFLVHeader->GetBuffer(),
m_pFF->m_pFLVHeader->GetSize());
// Advance the pointer
pBuf += m_pFF->m_pFLVHeader->GetSize();
ulLen -= m_pFF->m_pFLVHeader->GetSize();
}
if (bUseTagHdr)
{
// Copy the FLV tag header
memcpy(pBuf, m_pFF->m_pFLVTagHeader->GetBuffer(),
m_pFF->m_pFLVTagHeader->GetSize());
// Advance the pointer
pBuf += m_pFF->m_pFLVTagHeader->GetSize();
ulLen -= m_pFF->m_pFLVTagHeader->GetSize();
}
// Copy the FLV data
memcpy(pBuf, pBufferIn->GetBuffer(), pBufferIn->GetSize());
// Advance the pointer
pBuf += pBufferIn->GetSize();
ulLen -= pBufferIn->GetSize();
}
}
return retVal;
}
HX_RESULT
CInterleavedPayload::OnSeek(UINT32 ulSeekTime)
{
m_ulLastInterleavedTimeStamp = 0;
// If we are producing an interleaved stream and
// we are seeking back to 0, then use the
// data offset from the FLV header rather than
// the value in the seek table.
if (ulSeekTime == 0)
{
m_pFF->m_ulSeekOffsetRequested = m_pFF->m_cHeader.GetDataOffset();
}
return HXR_OK;
}
HX_RESULT
CInterleavedPayload::OnEndOfData(IHXBuffer* pBuffer, REF(IHXPacket*) pPacket)
{
// We need to provide the very end of the file as well
// in order to match the file size we have specified.
//
// Create a packet
pPacket = NULL;
HX_RESULT retVal = CreatePacketCCF(pPacket, m_pContext);
if (SUCCEEDED(retVal))
{
// Create the buffer for the interleaved packet
IHXBuffer* pPktBuffer = NULL;
retVal = CreateInterleavedBuffer(pBuffer, pPktBuffer, FALSE);
if (SUCCEEDED(retVal))
{
// Set the packet values
retVal = pPacket->Set(pPktBuffer,
m_ulLastInterleavedTimeStamp, // timestamp
0, // stream 0
HX_ASM_SWITCH_OFF, // ASM flags
1); // ASM rule
}
HX_RELEASE(pPktBuffer);
}
return retVal;
}
_______________________________________________
Datatype-cvs mailing list
Datatype-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/datatype-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic