AudioTypeG72X.cc revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1992-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <AudioTypeG72X.h>
// class AudioTypeG72X methods
// G.721 & G.723 compress/decompress
// Constructor
{
initialized = FALSE;
}
// Destructor
{
}
// Test conversion possibilities.
AudioHdr h) const // target header
{
// g72x conversion code handles mono 16-bit pcm, ulaw, alaw
if (h.channels != 1)
return (FALSE);
switch (h.encoding) {
case LINEAR:
if ((h.samples_per_unit != 1) ||
(h.bytes_per_unit != 2))
return (FALSE);
break;
case ALAW:
case ULAW:
if ((h.samples_per_unit != 1) ||
(h.bytes_per_unit != 1))
return (FALSE);
break;
case G721:
if ((h.samples_per_unit != 2) ||
(h.bytes_per_unit != 1))
return (FALSE);
break;
case G723:
if (h.samples_per_unit != 8)
return (FALSE);
// XXX - 5-bit G.722 not supported yet
if (h.bytes_per_unit != 3)
return (FALSE);
break;
case FLOAT:
default:
return (FALSE);
}
return (TRUE);
}
// Convert buffer to the specified type
// May replace the buffer with a new one, if necessary
{
int cnt;
unsigned char *inptr;
unsigned char *outptr;
return (AUDIO_ERR_BADARG);
}
// Make sure we're not being asked to do the impossible
return (err);
}
return (AUDIO_ERR_HDRINVAL);
// if conversion is a no-op, just return success
return (AUDIO_SUCCESS);
}
// Add some padding to the output buffer
// Allocate a new buffer
if (outbuf == 0)
return (AUDIO_UNIXERROR);
delete outbuf;
return (err);
}
// Convert from the input type to the output type
if (nbytes == 0)
goto cleanup;
case ALAW:
case ULAW:
case LINEAR:
case G721:
if (!initialized) {
initialized = TRUE;
}
break;
case G723:
if (!initialized) {
initialized = TRUE;
}
break;
default:
err = AUDIO_ERR_HDRINVAL; break;
}
break;
case G721:
case ALAW:
case ULAW:
case LINEAR:
if (!initialized) {
initialized = TRUE;
}
break;
default:
err = AUDIO_ERR_HDRINVAL; break;
}
break;
case G723:
case ALAW:
case ULAW:
case LINEAR:
if (!initialized) {
initialized = TRUE;
}
break;
default:
err = AUDIO_ERR_HDRINVAL; break;
}
break;
default:
err = AUDIO_ERR_HDRINVAL; break;
}
if (err) {
delete outbuf;
return (err);
}
// This will delete the buffer
inbuf->Dereference();
// Set the valid data length
return (AUDIO_SUCCESS);
}
// Flush out any leftover state, appending to supplied buffer
{
AudioHdr h;
unsigned char tmpbuf[32];
if (!initialized)
return (AUDIO_SUCCESS);
initialized = FALSE;
return (AUDIO_SUCCESS);
switch (h.encoding) {
case G721:
case G723:
switch (h.encoding) {
case G721:
break;
case G723:
break;
}
// Copy to the supplied buffer
if (cnt > 0) {
if (err)
return (err);
}
break;
default:
break;
}
return (AUDIO_SUCCESS);
}