[prev in list] [next in list] [prev in thread] [next in thread] 

List:       helix-datatype-cvs
Subject:    [Datatype-cvs] wav/common/util Umakefil, NONE, 1.1 writewav.cpp,
From:       ehyche () helixcommunity ! org
Date:       2008-12-17 20:00:19
Message-ID: 200812172001.mBHK1N9D004486 () mailer ! progressive-comp ! com
[Download RAW message or body]

Update of /cvsroot/datatype/wav/common/util
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv28982

Added Files:
	Umakefil writewav.cpp 
Log Message:
Description
----------------------------------------------
This CR adds support for a "capture" fileformat; that is, a fileformat plugin which \
claims JSR135 "capture://" URLs. For example, you can give the capture fileformat \
plugin an URL of:

splay capture://audio_video

and it will capture and display audio and video from the default audio and video \
capture devices using all the default settings.

Right now I am planning on checking in the capture fileformat to \
datatype/capture/fileformat, but I'm open to other locations, if others feel a \
different location would be more appropriate.

Files Added
--------------------------------------------
datatype/capture/fileformat/* - capture fileformat
datatype/wav/common/util/* - added utility functions to write out WAV file

Files Modified
--------------------------------------------
client/core/hxplay.cpp
   - fix bug in scheme/extension claiming \
client/encodesvc/common/util/hxencodesvc_utils.cpp \
                client/encodesvc/common/util/pub/hxencodesvc_utils.h
   - add Producer SDK event strings
client/encodesvc/include/ihxtplugininfobase.h
   - remove HX_DISABLE_LOGGING when plugin helper destructs \
                client/encodesvc/recordengine/chxvideocapture.cpp
   - add default device property for video common/include/hxtypes.h
   - add MAX_INT64 definition
common/include/ihxtlogsystem.h
   - add HXLOG_CAPF logging 4cc
common/log/logobserverfile/hxtlogobserver.cpp
common/log/logobserverfile/hxtlogobserver.h
   - fix bug in file log observer where it subscribes
     twice to the observer manager, resulting in two
     log statement lines for each logging statement \
                common/log/logsystem/hxtwritermanager.cpp
   - remove noisy unnecessary assert
common/util/hxurlutil.cpp
common/util/pub/hxurlutil.h
   - enable URL option properties to all be set as buffer properties \
                datatype/common/audrend/audrend.cpp
   - add logging statement for OnPacket
helix.bif
   - add targets for datatype_capture_fileformat, datatype_wav_common_util,
     and splay_capture. splay_capture builds everything you need
     to test the capture fileformat.

Branches
--------------------------------------------
HEAD only



--- NEW FILE: Umakefil ---
# ***** BEGIN LICENSE BLOCK ***** 
# 
# Copyright Notices:
# 
# 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 ***** 

UmakefileVersion(2,2)

project.AddModuleIncludes("common/include",
                          "common/runtime/pub",
                          "common/util/pub",
                          "common/container/pub",
                          "common/dbgtool/pub")

project.AddSources("writewav.cpp")

LibraryTarget("wavcomlib")

DependTarget()


--- NEW FILE: writewav.cpp ---
/* ***** BEGIN LICENSE BLOCK ***** 
 * 
 * Copyright Notices:
 * 
 * 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 "pckunpck.h"
#include "hlxclib/stdio.h"

#define HX_WAV_FOURCC_RIFF       0x52494646
#define HX_WAV_FOURCC_WAVE       0x57415645
#define HX_WAV_FOURCC_fmt        0x666d7420
#define HX_WAV_FOURCC_data       0x64617461
#define HX_WAV_FORMAT_PCM        0x0001

HX_RESULT WriteWAVHeader(const char* pszFileName, UINT32 ulSampleRate, UINT32 \
ulNumChannels, UINT32 ulBitsPerSample) {
    HX_RESULT retVal = HXR_INVALID_PARAMETER;

    // Only works for numChannels <= 2 now
    if (pszFileName && ulSampleRate && ulBitsPerSample && ulNumChannels && \
ulNumChannels <= 2)  {
        // Set the return value
        retVal = HXR_FAIL;
        // Try and open the file, overwriting if necessary
        FILE* fp = fopen(pszFileName, "wb");
        if (fp)
        {
            // Pack the WAV header into the ucTmp buffer
            BYTE   ucTmp[44];
            BYTE*  pTmp             = &ucTmp[0];
            UINT32 ulTmp            = sizeof(ucTmp);
            UINT32 ulBytesPerSample = ulBitsPerSample / 8;
            UINT32 ulByteRate       = ulSampleRate * ulNumChannels * \
ulBytesPerSample;  UINT32 ulBlockAlign     = ulNumChannels * ulBytesPerSample;
            // Pack the RIFF four cc
            PackUINT32BEInc(&pTmp, &ulTmp, HX_WAV_FOURCC_RIFF);
            // Pack 0 for the RIFF chunk size - update in UpdateWAVHeader.
            PackUINT32BEInc(&pTmp, &ulTmp, 0);
            // Pack the WAVE four cc
            PackUINT32BEInc(&pTmp, &ulTmp, HX_WAV_FOURCC_WAVE);
            // Pack the 'fmt ' subchunk four cc
            PackUINT32BEInc(&pTmp, &ulTmp, HX_WAV_FOURCC_fmt);
            // Pack the fmt subchunk size
            PackUINT32LEInc(&pTmp, &ulTmp, 16);
            // Pack the audio format
            PackUINT16LEInc(&pTmp, &ulTmp, (UINT16) HX_WAV_FORMAT_PCM);
            // Pack the number of channels
            PackUINT16LEInc(&pTmp, &ulTmp, (UINT16) ulNumChannels);
            // Pack the sample rate
            PackUINT32LEInc(&pTmp, &ulTmp, ulSampleRate);
            // Pack the byte rate
            PackUINT32LEInc(&pTmp, &ulTmp, ulByteRate);
            // Pack the block align
            PackUINT16LEInc(&pTmp, &ulTmp, (UINT16) ulBlockAlign);
            // Pack the bits per sample
            PackUINT16LEInc(&pTmp, &ulTmp, (UINT16) ulBitsPerSample);
            // Pack the 'data' subchunk four cc
            PackUINT32BEInc(&pTmp, &ulTmp, HX_WAV_FOURCC_data);
            // Pack the data subchunk size (0 for now - update in UpdateWavHeader)
            PackUINT32LEInc(&pTmp, &ulTmp, 0);
            /* Write out the wav header */
            INT32 lNumBytesWritten = fwrite(&ucTmp[0], 1, 44, fp);
            if (lNumBytesWritten == 44)
            {
                // Clear the return value
                retVal = HXR_OK;
            }
            // Close the file
            fclose(fp);
        }
    }

    return retVal;
}

void SwapSamples(BYTE* pBuf, UINT32 ulLen)
{
    if (pBuf && ulLen)
    {
        UINT32 i = 0;
        for (i = 0; i < ulLen; i += 2)
        {
            BYTE ucTmp = pBuf[i];
            pBuf[i]    = pBuf[i+1];
            pBuf[i+1]  = ucTmp;
        }
    }
}

HX_RESULT WriteSamplesToWAVFile(const char* pszFileName, BYTE* pBuf, UINT32 \
ulBufSize, HXBOOL bNeedSwap) {
    HX_RESULT retVal = HXR_INVALID_PARAMETER;

    // Only works for numChannels <= 2 now
    if (pszFileName && pBuf && ulBufSize)
    {
        // Set the return value
        retVal = HXR_FAIL;
        // Try and open the file for appending
        FILE* fp = fopen(pszFileName, "ab");
        if (fp)
        {
            // Do we need to swap?
            if (bNeedSwap)
            {
                SwapSamples(pBuf, ulBufSize);
            }
            // Write the samples out
            INT32 lBytesWritten = (INT32) fwrite(pBuf, 1, (size_t) ulBufSize, fp);
            if (lBytesWritten == ((INT32) ulBufSize))
            {
                // Clear the return value
                retVal = HXR_OK;
            }
            // Close the file
            fclose(fp);
        }
    }

    return retVal;
}

HX_RESULT UpdateWAVHeader(const char* pszFileName)
{
    HX_RESULT retVal = HXR_INVALID_PARAMETER;

    if (pszFileName)
    {
        // Set the return value
        retVal = HXR_FAIL;
        // Re-open the file for updating
        FILE* fp = fopen(pszFileName, "r+b");
        if (fp)
        {
            BYTE   ucTmp[4];
            UINT32 ulFileSize    = 0;
            UINT32 ulRIFFSize    = 0;
            UINT32 ulDataSize    = 0;
            BYTE*  pTmp          = NULL;
            UINT32 ulLen         = 0;
            INT32  lBytesWritten = 0;
            // Compute the RIFF chunk size and the data chunk size from the size of \
the file.  fseek(fp, 0, SEEK_END);
            ulFileSize = (UINT32) ftell(fp);
            ulRIFFSize = ulFileSize - 8;
            ulDataSize = ulFileSize - 44;
            // Seek to the RIFF chunk size
            fseek(fp, 4, SEEK_SET);
            // Set up the packing buffer
            pTmp  = &ucTmp[0];
            ulLen = 4;
            // Pack the RIFF chunk size
            PackUINT32LEInc(&pTmp, &ulLen, ulRIFFSize);
            // Write out the buffer
            lBytesWritten = (INT32) fwrite(&ucTmp[0], 1, 4, fp);
            if (lBytesWritten == 4)
            {
                // Seek to the beginning of the data chunk size
                fseek(fp, 40, SEEK_SET);
                // Set up the packing buffer
                pTmp  = &ucTmp[0];
                ulLen = sizeof(ucTmp);
                // Pack the data chunk size
                PackUINT32LEInc(&pTmp, &ulLen, ulDataSize);
                // Write out the buffer
                lBytesWritten = (INT32) fwrite(&ucTmp[0], 1, 4, fp);
                if (lBytesWritten == 4)
                {
                    // Clear the return value
                    retVal = HXR_OK;
                }
            }
            // Close the file
            fclose(fp);
        }
    }

    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