コード例 #1
0
static void mp3_close(struct ast_filestream *s)
{
	struct mp3_private *p = s->_private;

	ExitMP3(&p->mp);
	return;
}
コード例 #2
0
ファイル: mpglib.c プロジェクト: OS2World/LIB-SDL-2014
static void MPGLIB_close(Sound_Sample *sample)
{
    Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
    mpglib_t *mpg = ((mpglib_t *) internal->decoder_private);
    ExitMP3(&mpg->mp);
    free(mpg);
} /* MPGLIB_close */
コード例 #3
0
void DecodeEngine_Destroy(void* pEng)
{
	DecodeEngine* pEngine=(DecodeEngine*)pEng;

	ExitMP3(&pEngine->Decoder);

	delete pEngine;
}
コード例 #4
0
int hip_decode_exit(hip_t hip)
{
    if (hip) {
        ExitMP3(hip);
    }

    return 0;
}
コード例 #5
0
ファイル: MpgLibDLL.c プロジェクト: IMSoP/CDex
DLLEXPORT MPGLIB_ERR MpgLib_CloseStream(H_STREAM hStream)
{
	/* deinitialize the decoder */
	ExitMP3(&mp);

	/* return success */
	return MPGLIB_OK;
}
コード例 #6
0
ファイル: mpglib.c プロジェクト: OS2World/LIB-SDL-2014
static int MPGLIB_rewind(Sound_Sample *sample)
{
    Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
    mpglib_t *mpg = ((mpglib_t *) internal->decoder_private);
    BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);

    /* this is just resetting some fields in a structure; it's very fast. */
    ExitMP3(&mpg->mp);
    InitMP3(&mpg->mp);
    mpg->outpos = mpg->outleft = 0;
    return(1);
} /* MPGLIB_rewind */
コード例 #7
0
ファイル: mp3DecoderPlugin.cpp プロジェクト: mariuz/haiku
status_t
mp3Decoder::Decode(void *buffer, int64 *frameCount,
				   media_header *mediaHeader, media_decode_info *info /* = 0 */)
{
	status_t last_err = B_LAST_BUFFER_ERROR;
	uint8 * out_buffer = static_cast<uint8 *>(buffer);
	int32	out_bytes_needed = fOutputBufferSize;
	int32	out_bytes = 0;

	fStartTime = (bigtime_t)(fSampleNo *1000000LL / fFrameRate);
	mediaHeader->start_time = fStartTime;

	while (out_bytes_needed > 0) {

		if (fNeedSync) {
			TRACE("mp3Decoder::Decode: syncing...\n");
			ExitMP3(&fMpgLibPrivate);
			InitMP3(&fMpgLibPrivate);
			fDecodingError = false;
			fResidualBytes = 0;
			// fNeedSync is reset in DecodeNextChunk
		}

		if (fDecodingError)
			return B_ERROR;

		if (fResidualBytes) {
			int32 bytes = min_c(fResidualBytes, out_bytes_needed);
			memcpy(out_buffer, fResidualBuffer, bytes);
			fResidualBuffer += bytes;
			fResidualBytes -= bytes;
			out_buffer += bytes;
			out_bytes += bytes;
			out_bytes_needed -= bytes;
			
			continue;
		}
		
		last_err = DecodeNextChunk();
		if (last_err != B_OK) {
			fDecodingError = true;
			break;
		}
	}

	*frameCount = out_bytes / fFrameSize;
	fSampleNo += *frameCount;

	TRACE("framecount %Ld, time %.6f\n", *frameCount, mediaHeader->start_time / 1000000.0);
	return (out_bytes > 0) ? B_OK : last_err;
}
コード例 #8
0
void DecodeEngine_Flush(void* pEng)
{
	DecodeEngine* pEngine=(DecodeEngine*)pEng;

	//complete reinit
	ExitMP3(&pEngine->Decoder);
	InitMP3(&pEngine->Decoder);
	
	/*while(pEngine->Decoder.tail!=NULL)
		remove_buf(&pEngine->Decoder);
	pEngine->Decoder.bsize=0;

	pEngine->Decoder.header_parsed=0;
	pEngine->Decoder.side_parsed=0;
	pEngine->Decoder.data_parsed=0;
	pEngine->Decoder.sync_bitstream=1;*/
}
コード例 #9
0
static int mp3_queue(struct ast_filestream *s)
{
	struct mp3_private *p = s->_private;
	int res = 0, bytes = 0;

	if(p->seek) {
		ExitMP3(&p->mp);
		InitMP3(&p->mp, OUTSCALE);
		fseek(s->f, 0, SEEK_SET);
		p->sbuflen = p->dbuflen = p->offset = 0;
		while(p->offset < p->seek) {
			if(mp3_squeue(s))
				return -1;
			while(p->offset < p->seek && ((res = mp3_dqueue(s))) == MP3_OK) {
				for(bytes = 0 ; bytes < p->dbuflen ; bytes++) {
					p->dbufoffset++;
					p->offset++;
					if(p->offset >= p->seek)
						break;
				}
			}
			if(res == MP3_ERR)
				return -1;
		}

		p->seek = 0;
		return 0;
	}
	if(p->dbuflen == 0) {
		if(p->sbuflen) {
			res = mp3_dqueue(s);
			if(res == MP3_ERR)
				return -1;
		}
		if(! p->sbuflen || res != MP3_OK) {
			if(mp3_squeue(s))
				return -1;
		}

	}

	return 0;
}
コード例 #10
0
ファイル: mpglib_interface.c プロジェクト: At-sushi/lame
int
lame_decode_exit(void)
{
    ExitMP3(&mp);
    return 0;
}
コード例 #11
0
ファイル: mpglib_interface.c プロジェクト: cchatterj/isabel
int
lame_decode_exit(MPSTR * mp)
{
    ExitMP3(mp);
    return 0;
}
コード例 #12
0
bool MP3decoder::CloseStream()
{ 
	ExitMP3(&mp);
	return 1;

}
コード例 #13
0
ファイル: mp3DecoderPlugin.cpp プロジェクト: mariuz/haiku
mp3Decoder::~mp3Decoder()
{
	ExitMP3(&fMpgLibPrivate);
	delete [] fDecodeBuffer;
}
コード例 #14
0
ファイル: mpgplay.c プロジェクト: mentat/tehDJ
int main(int argc, char **argv){

	char		*bufout;
	char		*bufin;
	path_id		path,devpath;
	error_code	error;
	u_int32		bufsize_out = OUT_BUF_SIZE;
	u_int32		bufsize_in = IN_BUF_SIZE;
	u_int32		count;
	int			inlen,outlen;
	char		*compbuf=NULL;
	int			compbuflen=0,compbufpos=0;
	int			status=MP3_OK;
	int			i;
	struct 		mpstr mp;
	int 		iflag=0;

	if (argc != 3)
	{
		printf("Play MP3 file\n");
		printf("Usage: mpgplay <filename><device>\n");
		exit(1);
	}
	/* set up signal handler */
	intercept (sighand);

	/* Initialize the MP3 decoder */
	InitMP3(&mp);
	
	if ((error = _os_open(argv[1], FAM_READ, &path)) != SUCCESS) {
		return error;
	}
    
    /* Prepare the Sound device */
    if ((error = _os_open(argv[2], FAM_WRITE, &devpath)) != SUCCESS) {
		return error;
    }

    if ((error = _os_srqmem (&bufsize_in, (void**)&bufin, 0)) != SUCCESS) {
		return error;
	}

    if ((error = _os_srqmem (&bufsize_out, (void**)&bufout, 0)) != SUCCESS) {
		return error;
	}


	sigval = SMAP_DONE_SIG; /* Sound is free */

	#if defined(SHOW_TIME_INFO)
	time (&initial_time);
	#endif

	while(status != MP3_ERR){
	
		count = IN_BUF_SIZE;

	    /* read the data */
    	if ((error = _os_read(path, bufin, &count)) != SUCCESS){
	      if (error == EOS_EOF) break; /* done */
    	  else return error;
		}

		inlen = count;

		/* Initialize buffer */

		outlen = compbufpos = compbuflen = 0;

		status = decodeMP3(&mp,bufin,inlen,bufout,OUT_BUF_SIZE,&outlen);

		if (!iflag){
			printf("Playing %s [%s - %dkbs]\n",
				argv[1],
					mp.fr.stereo?"Stereo":"Mono",
						frequencies[mp.fr.sampling_frequency]);


			#if defined(SHOW_FRAME)
				printf("FRAME: stereo %d jsbound %d single %d lsf %d\n",
			    mp.fr.stereo,
			    mp.fr.jsbound,
			    mp.fr.single,
			    mp.fr.lsf);
				printf("mpeg25 %d header_change %d lay %d error_protection %d\n",
			    mp.fr.mpeg25,
			    mp.fr.header_change,
			    mp.fr.lay,
			    mp.fr.error_protection);
				printf("bitrate_index %d sampling_frequency %d padding %d extension %d\n",
			    mp.fr.bitrate_index,
			    mp.fr.sampling_frequency,
			    mp.fr.padding,
			    mp.fr.extension);
				printf("mode %d mode_ext %d copyright %d original %d\n",
			    mp.fr.mode,
			    mp.fr.mode_ext,
			    mp.fr.copyright,
			    mp.fr.original);
				printf("emphasis %d framesize %d\n",
			    mp.fr.emphasis,
			    mp.fr.framesize);
			
			#endif



			iflag=1;

		}

		while(status == MP3_OK){


			/* Check buffer size */
			if ((compbufpos + outlen) > compbuflen || compbuf == NULL)
				{
				compbuflen = compbufpos+outlen;
				compbuf = (char *) realloc(compbuf,compbuflen); 
				}

			memcpy(compbuf+compbufpos,bufout,outlen);
			compbufpos+=outlen;

			status = decodeMP3(&mp,NULL,0,bufout,OUT_BUF_SIZE,&outlen);

		}


		if (compbufpos)
		{

			int blks =  compbufpos / SND_BLK_SIZE;
			int residual = compbufpos - (blks*SND_BLK_SIZE);


			#if defined(SHOW_TIME_INFO)
			{
				time (&current_time);
			    ts_time_decompose ( (unsigned long)difftime (current_time, initial_time));
				total_blks += (blks+1);
			}
			#endif


			/* Wait for buffer slot to empty */
		
			sigmask(1);
			if (sigval != SMAP_DONE_SIG){
  				tsleep(0);		
			} else 
				sigmask(-1);

			sigval = 0; 

		 	if (compbufpos > sound_buffer_size)
	 		{


				sound_buffer = (u_char *) realloc(sound_buffer,compbufpos); 

			}

				sound_buffer_size = compbufpos;

				memcpy(sound_buffer,compbuf,sound_buffer_size);

				/*
				 * Fill up the sound maps
				*/

				for(i=0;i<blks;i++)
				{

					smap[i].num_channels =  mp.fr.stereo;
					smap[i].sample_rate = frequencies[mp.fr.sampling_frequency]; 
					smap[i].coding_method = CODING_METHOD; 
					smap[i].sample_size = SAMPLE_SIZE; 
					smap[i].cur_offset = 0;
					smap[i].loop_start = 0;
					smap[i].loop_count = 1; 
					smap[i].loop_counter = 0; 
					smap[i].next = &smap[i+1];
					smap[i].trig_mask = 0;
					smap[i].trig_signal = 0;
					/* get the size of the data in this read */
					smap[i].buf_size = smap[i].loop_end = SND_BLK_SIZE; 
					smap[i].buf = &sound_buffer[i*SND_BLK_SIZE];


				}

				/* If we do not have residual then back up to last sound map 1st */

				if (residual==0)
					i--;

				/* Last block in chain */
				smap[i].num_channels =  mp.fr.stereo;
				smap[i].sample_rate = frequencies[mp.fr.sampling_frequency]; 
				smap[i].coding_method = CODING_METHOD; 
				smap[i].sample_size = SAMPLE_SIZE; 
				smap[i].cur_offset = 0;
				smap[i].loop_start = 0;
				smap[i].loop_count = 1; 
				smap[i].loop_counter = 0; 
				smap[i].next = NULL;
				smap[i].trig_mask = SND_TRIG_READY;
				smap[i].trig_signal = SMAP_DONE_SIG;
				/* get the size of the data in this read */
				smap[i].buf_size = smap[i].loop_end = residual?residual:SND_BLK_SIZE; 
				smap[i].buf = &sound_buffer[i*SND_BLK_SIZE];

				if ((error = _os_ss_snd_play(devpath, &smap[0], SND_NOBLOCK  )) != SUCCESS) {
					  return error;
				}

				compbufpos = 0;
		
		}

	}
	
	#if defined(SHOW_TIME_INFO)
	printf("\n");
	#endif

	
	/* Wait for buffer slot to empty */
		
	sigmask(1);
	if (sigval != SMAP_DONE_SIG){
			tsleep(0);		
	} else 
		sigmask(-1);


	/* Exit the MP3 decoder */
	ExitMP3(&mp);

	_os_srtmem(bufsize_in, (void *)bufin);
	_os_srtmem(bufsize_out, (void *)bufout);


}