ע ¼  
 ӹע
   ʾһ  |  ر
ܰʾ΢֤Ƶ΢ʺŰѹڣ°󶨣°΢  |  ر

_

_

 
 
 
 
 

־

 
 

ffmpegС WIN32 API WAV   

2013-03-13 20:33:56|  ࣺ ĬϷ |  ǩ |ٱ |ֺС 

  LOFTER ҵƬ  |

?

Posted on 2009-11-24 17:44 jacky_zz

˴vs2008±룬µffmpeg汾svnأMSYS+MinGW뻷룬δgoogle Դڴ
aacoggʽųʽ֪ΪΣffmpegлл·

1ffmpegС WIN32 API WAV  - redtea - ڲ#include <stdio.h>
2ffmpegС WIN32 API WAV  - redtea - ڲ#include <stdlib.h>
3ffmpegС WIN32 API WAV  - redtea - ڲ#include <windows.h>
4ffmpegС WIN32 API WAV  - redtea - ڲ#include <mmsystem.h>
5ffmpegС WIN32 API WAV  - redtea - ڲ
6ffmpegС WIN32 API WAV  - redtea - ڲ#pragma comment(lib, "winmm.lib")
7ffmpegС WIN32 API WAV  - redtea - ڲ
8ffmpegС WIN32 API WAV  - redtea - ڲ#ifdef __cplusplus
9ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲextern "C" ffmpegС WIN32 API WAV  - redtea - ڲ{
10ffmpegС WIN32 API WAV  - redtea - ڲ#endif
11ffmpegС WIN32 API WAV  - redtea - ڲ
12ffmpegС WIN32 API WAV  - redtea - ڲ#include "./include/avcodec.h"
13ffmpegС WIN32 API WAV  - redtea - ڲ#include "./include/avformat.h"
14ffmpegС WIN32 API WAV  - redtea - ڲ#include "./include/avutil.h"
15ffmpegС WIN32 API WAV  - redtea - ڲ#include "./include/mem.h"
16ffmpegС WIN32 API WAV  - redtea - ڲ
17ffmpegС WIN32 API WAV  - redtea - ڲ#ifdef __cplusplus
18ffmpegС WIN32 API WAV  - redtea - ڲ}
19ffmpegС WIN32 API WAV  - redtea - ڲ#endif
20ffmpegС WIN32 API WAV  - redtea - ڲ
21ffmpegС WIN32 API WAV  - redtea - ڲ#define BLOCK_SIZE 4608
22ffmpegС WIN32 API WAV  - redtea - ڲ#define BLOCK_COUNT 20
23ffmpegС WIN32 API WAV  - redtea - ڲ
24ffmpegС WIN32 API WAV  - redtea - ڲHWAVEOUT hWaveOut = NULL;
25ffmpegС WIN32 API WAV  - redtea - ڲ
26ffmpegС WIN32 API WAV  - redtea - ڲstatic void CALLBACK waveOutProc(HWAVEOUT, UINT, DWORD, DWORD, DWORD);
27ffmpegС WIN32 API WAV  - redtea - ڲstatic WAVEHDR* allocateBlocks(int size, int count);
28ffmpegС WIN32 API WAV  - redtea - ڲstatic void freeBlocks(WAVEHDR* blockArray);
29ffmpegС WIN32 API WAV  - redtea - ڲstatic void writeAudio(HWAVEOUT hWaveOut, LPSTR data, int size);
30ffmpegС WIN32 API WAV  - redtea - ڲ
31ffmpegС WIN32 API WAV  - redtea - ڲstatic CRITICAL_SECTION waveCriticalSection;
32ffmpegС WIN32 API WAV  - redtea - ڲstatic WAVEHDR* waveBlocks;
33ffmpegС WIN32 API WAV  - redtea - ڲstatic volatile unsigned int waveFreeBlockCount;
34ffmpegС WIN32 API WAV  - redtea - ڲstatic int waveCurrentBlock;
35ffmpegС WIN32 API WAV  - redtea - ڲ
36ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲtypedef struct AudioState ffmpegС WIN32 API WAV  - redtea - ڲ{
37ffmpegС WIN32 API WAV  - redtea - ڲ AVFormatContext* pFmtCtx;
38ffmpegС WIN32 API WAV  - redtea - ڲ AVCodecContext* pCodecCtx;
39ffmpegС WIN32 API WAV  - redtea - ڲ AVCodec* pCodec;
40ffmpegС WIN32 API WAV  - redtea - ڲ uint8_t audio_buf1[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
41ffmpegС WIN32 API WAV  - redtea - ڲ uint8_t* audio_buf;
42ffmpegС WIN32 API WAV  - redtea - ڲ unsigned int audio_buf_size;
43ffmpegС WIN32 API WAV  - redtea - ڲ int audio_buf_index;
44ffmpegС WIN32 API WAV  - redtea - ڲ AVPacket audio_pkt_temp;
45ffmpegС WIN32 API WAV  - redtea - ڲ AVPacket audio_pkt;
46ffmpegС WIN32 API WAV  - redtea - ڲ uint8_t* audio_pkt_data;
47ffmpegС WIN32 API WAV  - redtea - ڲ int audio_pkt_size;
48ffmpegС WIN32 API WAV  - redtea - ڲ int stream_index;
49ffmpegС WIN32 API WAV  - redtea - ڲ} AudioState;
50ffmpegС WIN32 API WAV  - redtea - ڲ
51ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲint audio_decode_frame(AudioState* pState) ffmpegС WIN32 API WAV  - redtea - ڲ{
52ffmpegС WIN32 API WAV  - redtea - ڲ
53ffmpegС WIN32 API WAV  - redtea - ڲ AVPacket* pkt_temp = &pState->audio_pkt_temp;
54ffmpegС WIN32 API WAV  - redtea - ڲ AVPacket* pkt = &pState->audio_pkt;
55ffmpegС WIN32 API WAV  - redtea - ڲ AVCodecContext* dec= pState->pCodecCtx;
56ffmpegС WIN32 API WAV  - redtea - ڲ int len = 0, data_size = sizeof(pState->audio_buf1);
57ffmpegС WIN32 API WAV  - redtea - ڲ int err = 0;
58ffmpegС WIN32 API WAV  - redtea - ڲ
59ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ for( ; ; ) ffmpegС WIN32 API WAV  - redtea - ڲ{
60ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ while (pkt_temp->size > 0) ffmpegС WIN32 API WAV  - redtea - ڲ{
61ffmpegС WIN32 API WAV  - redtea - ڲ data_size = sizeof(pState->audio_buf1);
62ffmpegС WIN32 API WAV  - redtea - ڲ len = avcodec_decode_audio3(dec, (int16_t*)pState->audio_buf1, &data_size, pkt_temp);
63ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ if (len < 0) ffmpegС WIN32 API WAV  - redtea - ڲ{
64ffmpegС WIN32 API WAV  - redtea - ڲ pkt_temp->size = 0;
65ffmpegС WIN32 API WAV  - redtea - ڲ break;
66ffmpegС WIN32 API WAV  - redtea - ڲ }
67ffmpegС WIN32 API WAV  - redtea - ڲ
68ffmpegС WIN32 API WAV  - redtea - ڲ pkt_temp->data += len;
69ffmpegС WIN32 API WAV  - redtea - ڲ pkt_temp->size -= len;
70ffmpegС WIN32 API WAV  - redtea - ڲ
71ffmpegС WIN32 API WAV  - redtea - ڲ if (data_size <= 0)
72ffmpegС WIN32 API WAV  - redtea - ڲ continue;
73ffmpegС WIN32 API WAV  - redtea - ڲ
74ffmpegС WIN32 API WAV  - redtea - ڲ pState->audio_buf = pState->audio_buf1;
75ffmpegС WIN32 API WAV  - redtea - ڲ return data_size;
76ffmpegС WIN32 API WAV  - redtea - ڲ }
77ffmpegС WIN32 API WAV  - redtea - ڲ
78ffmpegС WIN32 API WAV  - redtea - ڲ if (pkt->data)
79ffmpegС WIN32 API WAV  - redtea - ڲ av_free_packet(pkt);
80ffmpegС WIN32 API WAV  - redtea - ڲ
81ffmpegС WIN32 API WAV  - redtea - ڲ if((err = av_read_frame(pState->pFmtCtx, pkt)) < 0)
82ffmpegС WIN32 API WAV  - redtea - ڲ return -1;
83ffmpegС WIN32 API WAV  - redtea - ڲ
84ffmpegС WIN32 API WAV  - redtea - ڲ pkt_temp->data = pkt->data;
85ffmpegС WIN32 API WAV  - redtea - ڲ pkt_temp->size = pkt->size;
86ffmpegС WIN32 API WAV  - redtea - ڲ }
87ffmpegС WIN32 API WAV  - redtea - ڲ
88ffmpegС WIN32 API WAV  - redtea - ڲ return -1;
89ffmpegС WIN32 API WAV  - redtea - ڲ}
90ffmpegС WIN32 API WAV  - redtea - ڲ
91ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲint main(int argc, char* argv[]) ffmpegС WIN32 API WAV  - redtea - ڲ{
92ffmpegС WIN32 API WAV  - redtea - ڲ int err = 0;
93ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ AudioState audio_state = ffmpegС WIN32 API WAV  - redtea - ڲ{0};
94ffmpegС WIN32 API WAV  - redtea - ڲ unsigned int i = 0;
95ffmpegС WIN32 API WAV  - redtea - ڲ unsigned int ready = 0;
96ffmpegС WIN32 API WAV  - redtea - ڲ
97ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ OPENFILENAME ofn = ffmpegС WIN32 API WAV  - redtea - ڲ{0};
98ffmpegС WIN32 API WAV  - redtea - ڲ char filename[MAX_PATH];
99ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ WAVEFORMATEX wfx = ffmpegС WIN32 API WAV  - redtea - ڲ{0};
100ffmpegС WIN32 API WAV  - redtea - ڲ uint8_t buffer[BLOCK_SIZE];
101ffmpegС WIN32 API WAV  - redtea - ڲ uint8_t* pbuffer = buffer;
102ffmpegС WIN32 API WAV  - redtea - ڲ AVInputFormat* iformat = NULL;
103ffmpegС WIN32 API WAV  - redtea - ڲ
104ffmpegС WIN32 API WAV  - redtea - ڲ int audio_size = 0, data_size = 0;
105ffmpegС WIN32 API WAV  - redtea - ڲ int len = 0, len1 = 0, eof = 0, size = 0;
106ffmpegС WIN32 API WAV  - redtea - ڲ
107ffmpegС WIN32 API WAV  - redtea - ڲ memset(&ofn, 0, sizeof(OPENFILENAME));
108ffmpegС WIN32 API WAV  - redtea - ڲ ofn.lStructSize = sizeof(ofn);
109ffmpegС WIN32 API WAV  - redtea - ڲ ofn.hwndOwner = GetDesktopWindow();
110ffmpegС WIN32 API WAV  - redtea - ڲ ofn.lpstrFile = filename;
111ffmpegС WIN32 API WAV  - redtea - ڲ ofn.lpstrFile[0] = '\0';
112ffmpegС WIN32 API WAV  - redtea - ڲ ofn.nMaxFile = sizeof(filename) / sizeof(filename[0]);
113ffmpegС WIN32 API WAV  - redtea - ڲ ofn.lpstrFilter = _TEXT("All support files\0*.aac;*.ape;*.flac;*.mp3;*.mp4;*.mpc;*.ogg;*.tta;*.wma;*.wav\0");
114ffmpegС WIN32 API WAV  - redtea - ڲ ofn.nFilterIndex = 1;
115ffmpegС WIN32 API WAV  - redtea - ڲ ofn.lpstrFileTitle = NULL;
116ffmpegС WIN32 API WAV  - redtea - ڲ ofn.nMaxFileTitle = 0;
117ffmpegС WIN32 API WAV  - redtea - ڲ ofn.lpstrInitialDir = NULL;
118ffmpegС WIN32 API WAV  - redtea - ڲ ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
119ffmpegС WIN32 API WAV  - redtea - ڲ
120ffmpegС WIN32 API WAV  - redtea - ڲ if (GetOpenFileName(&ofn) == FALSE)
121ffmpegС WIN32 API WAV  - redtea - ڲ return 0;
122ffmpegС WIN32 API WAV  - redtea - ڲ
123ffmpegС WIN32 API WAV  - redtea - ڲ av_register_all();
124ffmpegС WIN32 API WAV  - redtea - ڲ
125ffmpegС WIN32 API WAV  - redtea - ڲ err = av_open_input_file(&audio_state.pFmtCtx, filename, NULL, 0, NULL);
126ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ if(err < 0) ffmpegС WIN32 API WAV  - redtea - ڲ{
127ffmpegС WIN32 API WAV  - redtea - ڲ printf("can not open file %s.\n", filename);
128ffmpegС WIN32 API WAV  - redtea - ڲ return -1;
129ffmpegС WIN32 API WAV  - redtea - ڲ }
130ffmpegС WIN32 API WAV  - redtea - ڲ
131ffmpegС WIN32 API WAV  - redtea - ڲ err = av_find_stream_info(audio_state.pFmtCtx);
132ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ if(err < 0) ffmpegС WIN32 API WAV  - redtea - ڲ{
133ffmpegС WIN32 API WAV  - redtea - ڲ printf("can not find stream info of file %s.\n", filename);
134ffmpegС WIN32 API WAV  - redtea - ڲ return -1;
135ffmpegС WIN32 API WAV  - redtea - ڲ }
136ffmpegС WIN32 API WAV  - redtea - ڲ
137ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ for(i = 0; i < audio_state.pFmtCtx->nb_streams; i++) ffmpegС WIN32 API WAV  - redtea - ڲ{
138ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ if(audio_state.pFmtCtx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) ffmpegС WIN32 API WAV  - redtea - ڲ{
139ffmpegС WIN32 API WAV  - redtea - ڲ audio_state.pCodecCtx = audio_state.pFmtCtx->streams[i]->codec;
140ffmpegС WIN32 API WAV  - redtea - ڲ audio_state.stream_index = i;
141ffmpegС WIN32 API WAV  - redtea - ڲ ready = 1;
142ffmpegС WIN32 API WAV  - redtea - ڲ break;
143ffmpegС WIN32 API WAV  - redtea - ڲ }
144ffmpegС WIN32 API WAV  - redtea - ڲ }
145ffmpegС WIN32 API WAV  - redtea - ڲ
146ffmpegС WIN32 API WAV  - redtea - ڲ if(!ready)
147ffmpegС WIN32 API WAV  - redtea - ڲ return -1;
148ffmpegС WIN32 API WAV  - redtea - ڲ
149ffmpegС WIN32 API WAV  - redtea - ڲ audio_state.pCodec = avcodec_find_decoder(audio_state.pCodecCtx->codec_id);
150ffmpegС WIN32 API WAV  - redtea - ڲ if(!audio_state.pCodec || avcodec_open(audio_state.pCodecCtx, audio_state.pCodec) < 0)
151ffmpegС WIN32 API WAV  - redtea - ڲ return -1;
152ffmpegС WIN32 API WAV  - redtea - ڲ
153ffmpegС WIN32 API WAV  - redtea - ڲ wfx.nSamplesPerSec = audio_state.pCodecCtx->sample_rate;
154ffmpegС WIN32 API WAV  - redtea - ڲ switch(audio_state.pCodecCtx->sample_fmt)
155ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ ffmpegС WIN32 API WAV  - redtea - ڲ{
156ffmpegС WIN32 API WAV  - redtea - ڲ case SAMPLE_FMT_U8:
157ffmpegС WIN32 API WAV  - redtea - ڲ wfx.wBitsPerSample = 8;
158ffmpegС WIN32 API WAV  - redtea - ڲ break;
159ffmpegС WIN32 API WAV  - redtea - ڲ case SAMPLE_FMT_S16:
160ffmpegС WIN32 API WAV  - redtea - ڲ wfx.wBitsPerSample = 16;
161ffmpegС WIN32 API WAV  - redtea - ڲ break;
162ffmpegС WIN32 API WAV  - redtea - ڲ case SAMPLE_FMT_S32:
163ffmpegС WIN32 API WAV  - redtea - ڲ wfx.wBitsPerSample = 32;
164ffmpegС WIN32 API WAV  - redtea - ڲ break;
165ffmpegС WIN32 API WAV  - redtea - ڲ case SAMPLE_FMT_FLT:
166ffmpegС WIN32 API WAV  - redtea - ڲ wfx.wBitsPerSample = sizeof(double) * 8;
167ffmpegС WIN32 API WAV  - redtea - ڲ break;
168ffmpegС WIN32 API WAV  - redtea - ڲ default:
169ffmpegС WIN32 API WAV  - redtea - ڲ wfx.wBitsPerSample = 0;
170ffmpegС WIN32 API WAV  - redtea - ڲ break;
171ffmpegС WIN32 API WAV  - redtea - ڲ }
172ffmpegС WIN32 API WAV  - redtea - ڲ
173ffmpegС WIN32 API WAV  - redtea - ڲ wfx.nChannels = FFMIN(2, audio_state.pCodecCtx->channels);
174ffmpegС WIN32 API WAV  - redtea - ڲ wfx.cbSize = 0;
175ffmpegС WIN32 API WAV  - redtea - ڲ wfx.wFormatTag = WAVE_FORMAT_PCM;
176ffmpegС WIN32 API WAV  - redtea - ڲ wfx.nBlockAlign = (wfx.wBitsPerSample * wfx.nChannels) >> 3;
177ffmpegС WIN32 API WAV  - redtea - ڲ wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
178ffmpegС WIN32 API WAV  - redtea - ڲ
179ffmpegС WIN32 API WAV  - redtea - ڲ waveBlocks = allocateBlocks(BLOCK_SIZE, BLOCK_COUNT);
180ffmpegС WIN32 API WAV  - redtea - ڲ waveFreeBlockCount = BLOCK_COUNT;
181ffmpegС WIN32 API WAV  - redtea - ڲ waveCurrentBlock = 0;
182ffmpegС WIN32 API WAV  - redtea - ڲ
183ffmpegС WIN32 API WAV  - redtea - ڲ InitializeCriticalSection(&waveCriticalSection);
184ffmpegС WIN32 API WAV  - redtea - ڲ
185ffmpegС WIN32 API WAV  - redtea - ڲ // open wave out device
186ffmpegС WIN32 API WAV  - redtea - ڲ if(waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfx, (DWORD_PTR)waveOutProc,
187ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ (DWORD_PTR)&waveFreeBlockCount, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) ffmpegС WIN32 API WAV  - redtea - ڲ{
188ffmpegС WIN32 API WAV  - redtea - ڲ fprintf(stderr, "%s: unable to open wave mapper device\n", argv[0]);
189ffmpegС WIN32 API WAV  - redtea - ڲ ExitProcess(1);
190ffmpegС WIN32 API WAV  - redtea - ڲ }
191ffmpegС WIN32 API WAV  - redtea - ڲ
192ffmpegС WIN32 API WAV  - redtea - ڲ // play loop
193ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ for( ; ; ) ffmpegС WIN32 API WAV  - redtea - ڲ{
194ffmpegС WIN32 API WAV  - redtea - ڲ
195ffmpegС WIN32 API WAV  - redtea - ڲ len = BLOCK_SIZE;
196ffmpegС WIN32 API WAV  - redtea - ڲ size = 0;
197ffmpegС WIN32 API WAV  - redtea - ڲ pbuffer = buffer;
198ffmpegС WIN32 API WAV  - redtea - ڲ
199ffmpegС WIN32 API WAV  - redtea - ڲ if(eof)
200ffmpegС WIN32 API WAV  - redtea - ڲ break;
201ffmpegС WIN32 API WAV  - redtea - ڲ
202ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ while(len > 0) ffmpegС WIN32 API WAV  - redtea - ڲ{
203ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ if(audio_state.audio_buf_index >= (int)audio_state.audio_buf_size) ffmpegС WIN32 API WAV  - redtea - ڲ{
204ffmpegС WIN32 API WAV  - redtea - ڲ audio_size = audio_decode_frame(&audio_state);
205ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ if(audio_size < 0) ffmpegС WIN32 API WAV  - redtea - ڲ{
206ffmpegС WIN32 API WAV  - redtea - ڲ if(size > 0)
207ffmpegС WIN32 API WAV  - redtea - ڲ break;
208ffmpegС WIN32 API WAV  - redtea - ڲ
209ffmpegС WIN32 API WAV  - redtea - ڲ eof = 1;
210ffmpegС WIN32 API WAV  - redtea - ڲ break;
211ffmpegС WIN32 API WAV  - redtea - ڲ }
212ffmpegС WIN32 API WAV  - redtea - ڲ
213ffmpegС WIN32 API WAV  - redtea - ڲ audio_state.audio_buf_size = audio_size;
214ffmpegС WIN32 API WAV  - redtea - ڲ audio_state.audio_buf_index = 0;
215ffmpegС WIN32 API WAV  - redtea - ڲ }
216ffmpegС WIN32 API WAV  - redtea - ڲ
217ffmpegС WIN32 API WAV  - redtea - ڲ len1 = audio_state.audio_buf_size - audio_state.audio_buf_index;
218ffmpegС WIN32 API WAV  - redtea - ڲ if(len1 > len)
219ffmpegС WIN32 API WAV  - redtea - ڲ len1 = len;
220ffmpegС WIN32 API WAV  - redtea - ڲ
221ffmpegС WIN32 API WAV  - redtea - ڲ memcpy(pbuffer, (uint8_t *)audio_state.audio_buf + audio_state.audio_buf_index, len1);
222ffmpegС WIN32 API WAV  - redtea - ڲ
223ffmpegС WIN32 API WAV  - redtea - ڲ len -= len1;
224ffmpegС WIN32 API WAV  - redtea - ڲ pbuffer += len1;
225ffmpegС WIN32 API WAV  - redtea - ڲ size += len1;
226ffmpegС WIN32 API WAV  - redtea - ڲ audio_state.audio_buf_index += len1;
227ffmpegС WIN32 API WAV  - redtea - ڲ }
228ffmpegС WIN32 API WAV  - redtea - ڲ
229ffmpegС WIN32 API WAV  - redtea - ڲ writeAudio(hWaveOut, (char*)buffer, size);
230ffmpegС WIN32 API WAV  - redtea - ڲ }
231ffmpegС WIN32 API WAV  - redtea - ڲ
232ffmpegС WIN32 API WAV  - redtea - ڲ // wait for complete
233ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ for( ; ; ) ffmpegС WIN32 API WAV  - redtea - ڲ{
234ffmpegС WIN32 API WAV  - redtea - ڲ if(waveFreeBlockCount >= BLOCK_COUNT)
235ffmpegС WIN32 API WAV  - redtea - ڲ break;
236ffmpegС WIN32 API WAV  - redtea - ڲ
237ffmpegС WIN32 API WAV  - redtea - ڲ Sleep(10);
238ffmpegС WIN32 API WAV  - redtea - ڲ }
239ffmpegС WIN32 API WAV  - redtea - ڲ
240ffmpegС WIN32 API WAV  - redtea - ڲ for(i = 0; i < waveFreeBlockCount; i++)
241ffmpegС WIN32 API WAV  - redtea - ڲ if(waveBlocks[i].dwFlags & WHDR_PREPARED)
242ffmpegС WIN32 API WAV  - redtea - ڲ waveOutUnprepareHeader(hWaveOut, &waveBlocks[i], sizeof(WAVEHDR));
243ffmpegС WIN32 API WAV  - redtea - ڲ
244ffmpegС WIN32 API WAV  - redtea - ڲ DeleteCriticalSection(&waveCriticalSection);
245ffmpegС WIN32 API WAV  - redtea - ڲ freeBlocks(waveBlocks);
246ffmpegС WIN32 API WAV  - redtea - ڲ waveOutClose(hWaveOut);
247ffmpegС WIN32 API WAV  - redtea - ڲ
248ffmpegС WIN32 API WAV  - redtea - ڲ avcodec_close(audio_state.pCodecCtx);
249ffmpegС WIN32 API WAV  - redtea - ڲ
250ffmpegС WIN32 API WAV  - redtea - ڲ system("pause");
251ffmpegС WIN32 API WAV  - redtea - ڲ return 0;
252ffmpegС WIN32 API WAV  - redtea - ڲ}
253ffmpegС WIN32 API WAV  - redtea - ڲ
254ffmpegС WIN32 API WAV  - redtea - ڲstatic void writeAudio(HWAVEOUT hWaveOut, LPSTR data, int size)
255ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ{
256ffmpegС WIN32 API WAV  - redtea - ڲ WAVEHDR* current;
257ffmpegС WIN32 API WAV  - redtea - ڲ int remain;
258ffmpegС WIN32 API WAV  - redtea - ڲ
259ffmpegС WIN32 API WAV  - redtea - ڲ current = &waveBlocks[waveCurrentBlock];
260ffmpegС WIN32 API WAV  - redtea - ڲ
261ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ while(size > 0) ffmpegС WIN32 API WAV  - redtea - ڲ{
262ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ /**//*
263ffmpegС WIN32 API WAV  - redtea - ڲ * first make sure the header we're going to use is unprepared
264ffmpegС WIN32 API WAV  - redtea - ڲ */
265ffmpegС WIN32 API WAV  - redtea - ڲ if(current->dwFlags & WHDR_PREPARED)
266ffmpegС WIN32 API WAV  - redtea - ڲ waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR));
267ffmpegС WIN32 API WAV  - redtea - ڲ
268ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ if(size < (int)(BLOCK_SIZE - current->dwUser)) ffmpegС WIN32 API WAV  - redtea - ڲ{
269ffmpegС WIN32 API WAV  - redtea - ڲ memcpy(current->lpData + current->dwUser, data, size);
270ffmpegС WIN32 API WAV  - redtea - ڲ current->dwUser += size;
271ffmpegС WIN32 API WAV  - redtea - ڲ break;
272ffmpegС WIN32 API WAV  - redtea - ڲ }
273ffmpegС WIN32 API WAV  - redtea - ڲ
274ffmpegС WIN32 API WAV  - redtea - ڲ remain = BLOCK_SIZE - current->dwUser;
275ffmpegС WIN32 API WAV  - redtea - ڲ memcpy(current->lpData + current->dwUser, data, remain);
276ffmpegС WIN32 API WAV  - redtea - ڲ size -= remain;
277ffmpegС WIN32 API WAV  - redtea - ڲ data += remain;
278ffmpegС WIN32 API WAV  - redtea - ڲ current->dwBufferLength = BLOCK_SIZE;
279ffmpegС WIN32 API WAV  - redtea - ڲ
280ffmpegС WIN32 API WAV  - redtea - ڲ waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR));
281ffmpegС WIN32 API WAV  - redtea - ڲ waveOutWrite(hWaveOut, current, sizeof(WAVEHDR));
282ffmpegС WIN32 API WAV  - redtea - ڲ
283ffmpegС WIN32 API WAV  - redtea - ڲ EnterCriticalSection(&waveCriticalSection);
284ffmpegС WIN32 API WAV  - redtea - ڲ waveFreeBlockCount--;
285ffmpegС WIN32 API WAV  - redtea - ڲ LeaveCriticalSection(&waveCriticalSection);
286ffmpegС WIN32 API WAV  - redtea - ڲ
287ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ /**//*
288ffmpegС WIN32 API WAV  - redtea - ڲ * wait for a block to become free
289ffmpegС WIN32 API WAV  - redtea - ڲ */
290ffmpegС WIN32 API WAV  - redtea - ڲ while(!waveFreeBlockCount)
291ffmpegС WIN32 API WAV  - redtea - ڲ Sleep(10);
292ffmpegС WIN32 API WAV  - redtea - ڲ
293ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ /**//*
294ffmpegС WIN32 API WAV  - redtea - ڲ * point to the next block
295ffmpegС WIN32 API WAV  - redtea - ڲ */
296ffmpegС WIN32 API WAV  - redtea - ڲ waveCurrentBlock++;
297ffmpegС WIN32 API WAV  - redtea - ڲ waveCurrentBlock %= BLOCK_COUNT;
298ffmpegС WIN32 API WAV  - redtea - ڲ
299ffmpegС WIN32 API WAV  - redtea - ڲ current = &waveBlocks[waveCurrentBlock];
300ffmpegС WIN32 API WAV  - redtea - ڲ current->dwUser = 0;
301ffmpegС WIN32 API WAV  - redtea - ڲ }
302ffmpegС WIN32 API WAV  - redtea - ڲ}
303ffmpegС WIN32 API WAV  - redtea - ڲ
304ffmpegС WIN32 API WAV  - redtea - ڲstatic WAVEHDR* allocateBlocks(int size, int count)
305ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ{
306ffmpegС WIN32 API WAV  - redtea - ڲ char* buffer;
307ffmpegС WIN32 API WAV  - redtea - ڲ int i;
308ffmpegС WIN32 API WAV  - redtea - ڲ WAVEHDR* blocks;
309ffmpegС WIN32 API WAV  - redtea - ڲ DWORD totalBufferSize = (size + sizeof(WAVEHDR)) * count;
310ffmpegС WIN32 API WAV  - redtea - ڲ
311ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ /**//*
312ffmpegС WIN32 API WAV  - redtea - ڲ * allocate memory for the entire set in one go
313ffmpegС WIN32 API WAV  - redtea - ڲ */
314ffmpegС WIN32 API WAV  - redtea - ڲ if((buffer = (char*)HeapAlloc(
315ffmpegС WIN32 API WAV  - redtea - ڲ GetProcessHeap(),
316ffmpegС WIN32 API WAV  - redtea - ڲ HEAP_ZERO_MEMORY,
317ffmpegС WIN32 API WAV  - redtea - ڲ totalBufferSize
318ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ )) == NULL) ffmpegС WIN32 API WAV  - redtea - ڲ{
319ffmpegС WIN32 API WAV  - redtea - ڲ fprintf(stderr, "Memory allocation error\n");
320ffmpegС WIN32 API WAV  - redtea - ڲ ExitProcess(1);
321ffmpegС WIN32 API WAV  - redtea - ڲ }
322ffmpegС WIN32 API WAV  - redtea - ڲ
323ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ /**//*
324ffmpegС WIN32 API WAV  - redtea - ڲ * and set up the pointers to each bit
325ffmpegС WIN32 API WAV  - redtea - ڲ */
326ffmpegС WIN32 API WAV  - redtea - ڲ blocks = (WAVEHDR*)buffer;
327ffmpegС WIN32 API WAV  - redtea - ڲ buffer += sizeof(WAVEHDR) * count;
328ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ for(i = 0; i < count; i++) ffmpegС WIN32 API WAV  - redtea - ڲ{
329ffmpegС WIN32 API WAV  - redtea - ڲ blocks[i].dwBufferLength = size;
330ffmpegС WIN32 API WAV  - redtea - ڲ blocks[i].lpData = buffer;
331ffmpegС WIN32 API WAV  - redtea - ڲ buffer += size;
332ffmpegС WIN32 API WAV  - redtea - ڲ }
333ffmpegС WIN32 API WAV  - redtea - ڲ
334ffmpegС WIN32 API WAV  - redtea - ڲ return blocks;
335ffmpegС WIN32 API WAV  - redtea - ڲ}
336ffmpegС WIN32 API WAV  - redtea - ڲ
337ffmpegС WIN32 API WAV  - redtea - ڲstatic void freeBlocks(WAVEHDR* blockArray)
338ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ{
339ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ /**//*
340ffmpegС WIN32 API WAV  - redtea - ڲ * and this is why allocateBlocks works the way it does
341ffmpegС WIN32 API WAV  - redtea - ڲ */
342ffmpegС WIN32 API WAV  - redtea - ڲ HeapFree(GetProcessHeap(), 0, blockArray);
343ffmpegС WIN32 API WAV  - redtea - ڲ}
344ffmpegС WIN32 API WAV  - redtea - ڲ
345ffmpegС WIN32 API WAV  - redtea - ڲstatic void CALLBACK waveOutProc(
346ffmpegС WIN32 API WAV  - redtea - ڲ HWAVEOUT hWaveOut,
347ffmpegС WIN32 API WAV  - redtea - ڲ UINT uMsg,
348ffmpegС WIN32 API WAV  - redtea - ڲ DWORD dwInstance,
349ffmpegС WIN32 API WAV  - redtea - ڲ DWORD dwParam1,
350ffmpegС WIN32 API WAV  - redtea - ڲ DWORD dwParam2
351ffmpegС WIN32 API WAV  - redtea - ڲ )
352ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ{
353ffmpegС WIN32 API WAV  - redtea - ڲ int* freeBlockCounter = (int*)dwInstance;
354ffmpegС WIN32 API WAV  - redtea - ڲffmpegС WIN32 API WAV  - redtea - ڲ /**//*
355ffmpegС WIN32 API WAV  - redtea - ڲ * ignore calls that occur due to opening and closing the
356ffmpegС WIN32 API WAV  - redtea - ڲ * device.
357ffmpegС WIN32 API WAV  - redtea - ڲ */
358ffmpegС WIN32 API WAV  - redtea - ڲ if(uMsg != WOM_DONE)
359ffmpegС WIN32 API WAV  - redtea - ڲ return;
360ffmpegС WIN32 API WAV  - redtea - ڲ
361ffmpegС WIN32 API WAV  - redtea - ڲ EnterCriticalSection(&waveCriticalSection);
362ffmpegС WIN32 API WAV  - redtea - ڲ (*freeBlockCounter)++;
363ffmpegС WIN32 API WAV  - redtea - ڲ LeaveCriticalSection(&waveCriticalSection);
364ffmpegС WIN32 API WAV  - redtea - ڲ}

Feedback

# re: ffmpegС ظ

2009-11-24 17:47 by cexer

ʼо ffmpegעһ²

# re: ffmpegС[δ¼] ظ

2009-11-24 20:05 by Bill Hsu

FFmpegиLZ(_)

# re: ffmpegС ظ

2009-11-24 21:02 by jacky_zz

ҵijйϵ𣿿ҵ򸽴Դ룬Ȼ򵥡

# re: ffmpegС ظ

2009-11-24 21:19 by ëë

,ղ,ѧϰ

# re: ffmpegС ظ

2009-11-25 11:03 by jacky_zz

ҵܲaacoggˣԭffmpegڴҪav_mallocͷڴҪav_freeΪwindowslinuxڴڲͬffmpegڽʱҪڴǷ루ڴԼӿCPUĴٶȣڳwindowͨmallocͨķʽڴ治ȫڴģaacogg֡Ƶʽ֡Ȳһʱпʱ޸ĺĴ£߲Լ޸ļɡ
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#ifdef __cplusplus
extern "C" {
#endif
#include "./include/avcodec.h"
#include "./include/avformat.h"
#include "./include/avutil.h"
#include "./include/mem.h"
#ifdef __cplusplus
}
#endif
#define BLOCK_SIZE 4608
#define BLOCK_COUNT 20
HWAVEOUT hWaveOut = NULL;
static void CALLBACK waveOutProc(HWAVEOUT, UINT, DWORD, DWORD, DWORD);
static WAVEHDR* allocateBlocks(int size, int count);
static void freeBlocks(WAVEHDR* blockArray);
static void writeAudio(HWAVEOUT hWaveOut, LPSTR data, int size);
static CRITICAL_SECTION waveCriticalSection;
static WAVEHDR* waveBlocks;
static volatile unsigned int waveFreeBlockCount;
static int waveCurrentBlock;
typedef struct AudioState {
AVFormatContext* pFmtCtx;
AVCodecContext* pCodecCtx;
AVCodec* pCodec;
//uint8_t* audio_buf1[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
uint8_t* audio_buf1;
uint8_t* audio_buf;
unsigned int audio_buf_size; /* in bytes */
unsigned int buffer_size;
int audio_buf_index; /* in bytes */
AVPacket audio_pkt_temp;
AVPacket audio_pkt;
uint8_t* audio_pkt_data;
int audio_pkt_size;
int stream_index;
} AudioState;
int audio_decode_frame(AudioState* pState) {
AVPacket* pkt_temp = &pState->audio_pkt_temp;
AVPacket* pkt = &pState->audio_pkt;
AVCodecContext* dec= pState->pCodecCtx;
int len = 0, data_size = sizeof(pState->audio_buf1);
int err = 0;
for( ; ; ) {
while (pkt_temp->size > 0) {
// data_size = sizeof(pState->audio_buf1);
data_size = pState->buffer_size;
len = avcodec_decode_audio3(dec, (int16_t*)pState->audio_buf1, &data_size, pkt_temp);
if (len < 0) {
pkt_temp->size = 0;
break;
}
pkt_temp->data += len;
pkt_temp->size -= len;
if (data_size <= 0)
continue;
pState->audio_buf = pState->audio_buf1;
return data_size;
}
if (pkt->data)
av_free_packet(pkt);
if((err = av_read_frame(pState->pFmtCtx, pkt)) < 0)
return -1;
pkt_temp->data = pkt->data;
pkt_temp->size = pkt->size;
}
return -1;
}
int main(int argc, char* argv[]) {
int err = 0;
AudioState audio_state = {0};
unsigned int i = 0;
unsigned int ready = 0;
OPENFILENAME ofn = {0};
char filename[MAX_PATH];
WAVEFORMATEX wfx = {0};
uint8_t buffer[BLOCK_SIZE];
uint8_t* pbuffer = buffer;
AVInputFormat* iformat = NULL;
int audio_size = 0, data_size = 0;
int len = 0, len1 = 0, eof = 0, size = 0;
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetDesktopWindow();
ofn.lpstrFile = filename;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(filename) / sizeof(filename[0]);
ofn.lpstrFilter = _TEXT("All support files\0*.aac;*.ape;*.flac;*.mp3;*.mp4;*.mpc;*.ogg;*.tta;*.wma;*.wav\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == FALSE)
return 0;
av_register_all();
err = av_open_input_file(&audio_state.pFmtCtx, filename, NULL, 0, NULL);
if(err < 0) {
printf("can not open file %s.\n", filename);
return -1;
}
err = av_find_stream_info(audio_state.pFmtCtx);
if(err < 0) {
printf("can not find stream info of file %s.\n", filename);
return -1;
}
for(i = 0; i < audio_state.pFmtCtx->nb_streams; i++) {
if(audio_state.pFmtCtx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {
audio_state.pCodecCtx = audio_state.pFmtCtx->streams[i]->codec;
audio_state.stream_index = i;
ready = 1;
break;
}
}
if(!ready)
return -1;
audio_state.pCodec = avcodec_find_decoder(audio_state.pCodecCtx->codec_id);
if(!audio_state.pCodec || avcodec_open(audio_state.pCodecCtx, audio_state.pCodec) < 0)
return -1;
wfx.nSamplesPerSec = audio_state.pCodecCtx->sample_rate;
switch(audio_state.pCodecCtx->sample_fmt)
{
case SAMPLE_FMT_U8:
wfx.wBitsPerSample = 8;
break;
case SAMPLE_FMT_S16:
wfx.wBitsPerSample = 16;
break;
case SAMPLE_FMT_S32:
wfx.wBitsPerSample = 32;
break;
case SAMPLE_FMT_FLT:
wfx.wBitsPerSample = sizeof(double) * 8;
break;
default:
wfx.wBitsPerSample = 0;
break;
}
wfx.nChannels = FFMIN(2, audio_state.pCodecCtx->channels);
wfx.cbSize = 0;
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nBlockAlign = (wfx.wBitsPerSample * wfx.nChannels) >> 3;
wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
waveBlocks = allocateBlocks(BLOCK_SIZE, BLOCK_COUNT);
waveFreeBlockCount = BLOCK_COUNT;
waveCurrentBlock = 0;
InitializeCriticalSection(&waveCriticalSection);
// open wave out device
if(waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfx, (DWORD_PTR)waveOutProc,
(DWORD_PTR)&waveFreeBlockCount, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
fprintf(stderr, "%s: unable to open wave mapper device\n", argv[0]);
ExitProcess(1);
}
// allocate memory
audio_state.audio_buf1 =(uint8_t*)av_malloc(buffer_size);
audio_state.buffer_size = buffer_size;
// play loop
for( ; ; ) {
len = BLOCK_SIZE;
size = 0;
pbuffer = buffer;
if(eof)
break;
while(len > 0) {
if(audio_state.audio_buf_index >= (int)audio_state.audio_buf_size) {
audio_size = audio_decode_frame(&audio_state);
if(audio_size < 0) {
if(size > 0)
break;
eof = 1;
break;
}
audio_state.audio_buf_size = audio_size;
audio_state.audio_buf_index = 0;
}
len1 = audio_state.audio_buf_size - audio_state.audio_buf_index;
if(len1 > len)
len1 = len;
memcpy(pbuffer, (uint8_t *)audio_state.audio_buf + audio_state.audio_buf_index, len1);
len -= len1;
pbuffer += len1;
size += len1;
audio_state.audio_buf_index += len1;
}
writeAudio(hWaveOut, (char*)buffer, size);
}
// free allocated memory
av_free(audio_state.audio_buf1);
audio_state.audio_buf1 = NULL;
// wait for complete
for( ; ; ) {
if(waveFreeBlockCount >= BLOCK_COUNT)
break;
Sleep(10);
}
for(i = 0; i < waveFreeBlockCount; i++)
if(waveBlocks[i].dwFlags & WHDR_PREPARED)
waveOutUnprepareHeader(hWaveOut, &waveBlocks[i], sizeof(WAVEHDR));
DeleteCriticalSection(&waveCriticalSection);
freeBlocks(waveBlocks);
waveOutClose(hWaveOut);
avcodec_close(audio_state.pCodecCtx);
system("pause");
return 0;
}
static void writeAudio(HWAVEOUT hWaveOut, LPSTR data, int size)
{
WAVEHDR* current;
int remain;
current = &waveBlocks[waveCurrentBlock];
while(size > 0) {
/*
* first make sure the header we're going to use is unprepared
*/
if(current->dwFlags & WHDR_PREPARED)
waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR));
if(size < (int)(BLOCK_SIZE - current->dwUser)) {
memcpy(current->lpData + current->dwUser, data, size);
current->dwUser += size;
break;
}
remain = BLOCK_SIZE - current->dwUser;
memcpy(current->lpData + current->dwUser, data, remain);
size -= remain;
data += remain;
current->dwBufferLength = BLOCK_SIZE;
waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR));
waveOutWrite(hWaveOut, current, sizeof(WAVEHDR));
EnterCriticalSection(&waveCriticalSection);
waveFreeBlockCount--;
LeaveCriticalSection(&waveCriticalSection);
/*
* wait for a block to become free
*/
while(!waveFreeBlockCount)
Sleep(10);
/*
* point to the next block
*/
waveCurrentBlock++;
waveCurrentBlock %= BLOCK_COUNT;
current = &waveBlocks[waveCurrentBlock];
current->dwUser = 0;
}
}
static WAVEHDR* allocateBlocks(int size, int count)
{
char* buffer;
int i;
WAVEHDR* blocks;
DWORD totalBufferSize = (size + sizeof(WAVEHDR)) * count;
/*
* allocate memory for the entire set in one go
*/
if((buffer = (char*)HeapAlloc(
GetProcessHeap(),
HEAP_ZERO_MEMORY,
totalBufferSize
)) == NULL) {
fprintf(stderr, "Memory allocation error\n");
ExitProcess(1);
}
/*
* and set up the pointers to each bit
*/
blocks = (WAVEHDR*)buffer;
buffer += sizeof(WAVEHDR) * count;
for(i = 0; i < count; i++) {
blocks[i].dwBufferLength = size;
blocks[i].lpData = buffer;
buffer += size;
}
return blocks;
}
static void freeBlocks(WAVEHDR* blockArray)
{
/*
* and this is why allocateBlocks works the way it does
*/
HeapFree(GetProcessHeap(), 0, blockArray);
}
static void CALLBACK waveOutProc(
HWAVEOUT hWaveOut,
UINT uMsg,
DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2
)
{
int* freeBlockCounter = (int*)dwInstance;
/*
* ignore calls that occur due to opening and closing the
* device.
*/
if(uMsg != WOM_DONE)
return;
EnterCriticalSection(&waveCriticalSection);
(*freeBlockCounter)++;
LeaveCriticalSection(&waveCriticalSection);
}

# re: ffmpegС ظ

2009-12-21 18:44 by TS,MPEG2,dvbcר

ذ,û.avcodec-52.dll ޷.

# re: ffmpegС ظ

2009-12-22 11:41 by seliu

ҲһMSYS+MinGWоһffmpeg.MSYSʲӦlinuxģwindowsffmpeg sdk㹻ˡ
żûʱˣλϺcygwin+MinGWϣͬоһffmpeglinuxرʱǶʽµӦá

# re: ffmpegС ظ

2011-06-17 00:13 by f4s

ллĴ롣Ѿˡ

# re: ffmpegС ظ

2011-07-09 23:20 by ffish

л¥Ĵ롣av_read_frameиijͿֱӲ󲿷Ƶļˣ֣
pkt->stream_index = -1;
while(pkt->stream_index != pState->stream_index) {
if((err = av_read_frame(pState->pFmtCtx, pkt)) < 0)
return -1;
}

# re: ffmpegС ظ

2011-12-13 17:44 by glueless lace wigs

DzŪ

# re: ffmpegС[δ¼] ظ

2011-12-26 15:34 by jacky_zz

@glueless lace wigs
ǣҪDZ£Ͳˡ

# re: ffmpegС[δ¼] ظ

2012-01-25 01:57 by danny

ллjackzzѾţˣոWinCEһmp3flacapeoggwmawavúhappy

# re: ffmpegС ظ

2013-01-05 21:45 by cheaterlin

ҵQQ475316440~鷳һ£ڽ룬һЩ~thanks~
avcodec_decode_audio3((AVCodecContext *avctx, int16_t *samples,int *frame_size_ptr,AVPacket *avpkt))һ֡ݣдݣsamplesǰ˳У

 
 
Ķ(1137)| (0)
Ƽ ת

ʷϵĽ

LOFTERĸ

<#--־Ⱥ־--> <#--Ƽ־--> <#--ü¼--> <#--Ƽ--> <#--Ķ--> <#--ҳƼ--> <#--ʷϵĽ--> <#--Ƽ־--> <#--һƪһƪ--> <#-- ȶ --> <#-- Ź --> <#--ұģṹ--> <#--ģṹ--> <#--ģṹ--> <#--ͶƱ-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ҳ

ҵƬ - ͷ - ֻ - LOFTER APP - Ĵ˲

׹˾Ȩ ©1997-2017