ffmpeg update, set thread_count in acinerella to 1 (0 (auto) causes sync problems on HT CPUs), some changes in CVideoDecoderFFmpeg.cs
This commit is contained in:
1 parent
64dcc387e7
commit
4d3eed294b
13 files changed
+108
-78
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -422,10 +422,10 @@ namespace Vocaluxe.Lib.Sound
|
||||
|
||||
private Thread _DecoderThread;
|
||||
|
||||
AutoResetEvent EventDecode = new AutoResetEvent(false);
|
||||
private AutoResetEvent EventDecode = new AutoResetEvent(false);
|
||||
|
||||
Object MutexData = new Object();
|
||||
Object MutexSyncSignals = new Object();
|
||||
private Object _LockData = new Object();
|
||||
private Object _LockSyncSignals = new Object();
|
||||
|
||||
public PortAudioStream()
|
||||
{
|
||||
@@ -456,7 +456,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (MutexData)
|
||||
lock (_LockData)
|
||||
{
|
||||
return _NoMoreData && _data.BytesNotRead == 0L;
|
||||
}
|
||||
@@ -468,7 +468,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
get { return _Volume * 100f; }
|
||||
set
|
||||
{
|
||||
lock (MutexData)
|
||||
lock (_LockData)
|
||||
{
|
||||
_Volume = value / 100f;
|
||||
if (_Volume < 0f)
|
||||
@@ -484,7 +484,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (MutexData)
|
||||
lock (_LockData)
|
||||
{
|
||||
if (Finished)
|
||||
_SyncTimer.Pause();
|
||||
@@ -500,7 +500,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
set
|
||||
{
|
||||
_Paused = value;
|
||||
lock (MutexSyncSignals)
|
||||
lock (_LockData)
|
||||
{
|
||||
if (_Paused)
|
||||
_SyncTimer.Pause();
|
||||
@@ -615,12 +615,13 @@ namespace Vocaluxe.Lib.Sound
|
||||
outputParams.sampleFormat = PortAudio.PaSampleFormat.paInt16;
|
||||
outputParams.suggestedLatency = _outputDeviceInfo.defaultLowOutputLatency;
|
||||
|
||||
uint bufsize = (uint)CConfig.AudioBufferSize;
|
||||
errorCheck("OpenDefaultStream", PortAudio.Pa_OpenStream(
|
||||
out _Ptr,
|
||||
IntPtr.Zero,
|
||||
ref outputParams,
|
||||
format.SamplesPerSecond,
|
||||
(uint)CConfig.AudioBufferSize,
|
||||
bufsize,
|
||||
PortAudio.PaStreamFlags.paNoFlag,
|
||||
_paStreamCallback,
|
||||
data));
|
||||
@@ -645,7 +646,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
|
||||
public bool Skip(float Time)
|
||||
{
|
||||
lock (MutexSyncSignals)
|
||||
lock (_LockSyncSignals)
|
||||
{
|
||||
_SetStart = Time;
|
||||
_SetSkip = true;
|
||||
@@ -658,7 +659,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
#region Threading
|
||||
private void DoSkip()
|
||||
{
|
||||
lock (MutexData)
|
||||
lock (_LockData)
|
||||
{
|
||||
_Decoder.SetPosition(_Start);
|
||||
_CurrentTime = _Start;
|
||||
@@ -677,7 +678,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
{
|
||||
if (EventDecode.WaitOne(10))
|
||||
{
|
||||
lock (MutexSyncSignals)
|
||||
lock (_LockSyncSignals)
|
||||
{
|
||||
if (_SetSkip)
|
||||
{
|
||||
@@ -724,7 +725,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
byte[] Buffer;
|
||||
|
||||
bool DoIt = false;
|
||||
lock (MutexData)
|
||||
lock (_LockData)
|
||||
{
|
||||
if (!_skip && BUFSIZE - 10000L > _data.BytesNotRead)
|
||||
DoIt = true;
|
||||
@@ -739,7 +740,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
{
|
||||
if (_Loop)
|
||||
{
|
||||
lock (MutexSyncSignals)
|
||||
lock (_LockSyncSignals)
|
||||
{
|
||||
_CurrentTime = 0f;
|
||||
_Start = 0f;
|
||||
@@ -754,7 +755,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
return;
|
||||
}
|
||||
|
||||
lock (MutexData)
|
||||
lock (_LockData)
|
||||
{
|
||||
_data.Write(Buffer);
|
||||
_TimeCode = Timecode;
|
||||
@@ -804,7 +805,7 @@ namespace Vocaluxe.Lib.Sound
|
||||
return PortAudio.PaStreamCallbackResult.paContinue;
|
||||
}
|
||||
|
||||
lock (MutexData)
|
||||
lock (_LockData)
|
||||
{
|
||||
if (_NoMoreData || _data.BytesNotRead >= buf.Length)
|
||||
{
|
||||
|
||||
@@ -167,21 +167,6 @@ static int64_t io_seek(void *opaque, int64_t pos, int whence)
|
||||
return -1;
|
||||
}
|
||||
|
||||
//uint64_t global_video_pkt_pts = AV_NOPTS_VALUE;
|
||||
|
||||
int ac_get_buffer(struct AVCodecContext *c, AVFrame *pic) {
|
||||
int ret = avcodec_default_get_buffer(c, pic);
|
||||
uint64_t *pts = av_malloc(sizeof(uint64_t));
|
||||
*pts = AV_NOPTS_VALUE;
|
||||
pic->opaque = pts;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ac_release_buffer(struct AVCodecContext *c, AVFrame *pic){
|
||||
if (pic) av_freep(&pic->opaque);
|
||||
avcodec_default_release_buffer(c, pic);
|
||||
}
|
||||
|
||||
lp_ac_proberesult CALL_CONVT ac_probe_input_buffer(
|
||||
void* buf,
|
||||
int bufsize,
|
||||
@@ -533,7 +518,10 @@ void* ac_create_video_decoder(lp_ac_instance pacInstance, lp_ac_stream_info info
|
||||
if (!(pDecoder->pCodec = avcodec_find_decoder(pDecoder->pCodecCtx->codec_id))) {
|
||||
return NULL; //Codec could not have been found
|
||||
}
|
||||
|
||||
|
||||
pDecoder->pCodecCtx->thread_count = 1; //this is for HT CPUs, it should be
|
||||
// tested if there is a better solution
|
||||
|
||||
//Open codec
|
||||
if (avcodec_open2(pDecoder->pCodecCtx, pDecoder->pCodec, NULL) < 0) {
|
||||
return NULL; //Codec could not have been opened
|
||||
@@ -635,36 +623,34 @@ double ac_sync_video(lp_ac_package pPackage, lp_ac_decoder pDec, AVFrame *src_fr
|
||||
return pts;
|
||||
}
|
||||
|
||||
int ac_decode_video_package(lp_ac_package pPackage, lp_ac_video_decoder pDecoder, lp_ac_decoder pDec) {
|
||||
if (((lp_ac_package_data)pPackage)->ffpackage.size <= 0)
|
||||
return 0;
|
||||
|
||||
int ac_decode_video_package(lp_ac_package pPackage, lp_ac_video_decoder pDecoder, lp_ac_decoder pDec)
|
||||
{
|
||||
int finished = 0;
|
||||
double pts = 0;
|
||||
int len = 0;
|
||||
|
||||
AVPacket pkt_tmp = ((lp_ac_package_data)pPackage)->ffpackage;
|
||||
|
||||
while (pkt_tmp.size > 0) {
|
||||
len = avcodec_decode_video2(
|
||||
pDecoder->pCodecCtx, pDecoder->pFrame,
|
||||
&finished, &pkt_tmp);
|
||||
|
||||
if (len < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pkt_tmp.size -= len;
|
||||
pkt_tmp.data += len;
|
||||
}
|
||||
|
||||
/*
|
||||
avcodec_decode_video2(
|
||||
pDecoder->pCodecCtx, pDecoder->pFrame, &finished,
|
||||
&(((lp_ac_package_data)pPackage)->ffpackage));
|
||||
*/
|
||||
|
||||
if (finished) {
|
||||
if(((lp_ac_package_data)pPackage)->ffpackage.dts == AV_NOPTS_VALUE &&
|
||||
*(uint64_t*)pDecoder->pFrame->opaque != AV_NOPTS_VALUE ){
|
||||
pts = *(uint64_t*)pDecoder->pFrame->opaque;
|
||||
} else if(((lp_ac_package_data)pPackage)->ffpackage.dts != AV_NOPTS_VALUE){
|
||||
pts = ((lp_ac_package_data)pPackage)->ffpackage.dts;
|
||||
} else {
|
||||
pts = 0;
|
||||
}
|
||||
|
||||
if(((lp_ac_data)pDec->pacInstance)->pFormatCtx->streams[pPackage->stream_index]->start_time != AV_NOPTS_VALUE){
|
||||
pts -= ((lp_ac_data)pDec->pacInstance)->pFormatCtx->streams[pPackage->stream_index]->start_time;
|
||||
}
|
||||
|
||||
pts *= av_q2d(((lp_ac_data)pDec->pacInstance)->pFormatCtx->streams[pPackage->stream_index]->time_base);
|
||||
|
||||
pts = ac_sync_video(pPackage, pDec, pDecoder->pFrame, pts);
|
||||
pDec->timecode = pts;
|
||||
|
||||
if (finished != 0) {
|
||||
pDecoder->pSwsCtx = sws_getCachedContext(pDecoder->pSwsCtx,
|
||||
pDecoder->pCodecCtx->width, pDecoder->pCodecCtx->height, pDecoder->pCodecCtx->pix_fmt,
|
||||
pDecoder->pCodecCtx->width, pDecoder->pCodecCtx->height, convert_pix_format(pDecoder->decoder.pacInstance->output_format),
|
||||
@@ -678,6 +664,24 @@ int ac_decode_video_package(lp_ac_package pPackage, lp_ac_video_decoder pDecoder
|
||||
pDecoder->pCodecCtx->height,
|
||||
pDecoder->pFrameRGB->data,
|
||||
pDecoder->pFrameRGB->linesize);
|
||||
|
||||
|
||||
if(pkt_tmp.dts == AV_NOPTS_VALUE &&
|
||||
*(uint64_t*)pDecoder->pFrame->opaque != AV_NOPTS_VALUE ){
|
||||
pts = *(uint64_t*)pDecoder->pFrame->opaque;
|
||||
} else if(pkt_tmp.dts != AV_NOPTS_VALUE){
|
||||
pts = pkt_tmp.dts;
|
||||
}
|
||||
|
||||
if(((lp_ac_data)pDec->pacInstance)->pFormatCtx->streams[pPackage->stream_index]->start_time != AV_NOPTS_VALUE){
|
||||
pts -= ((lp_ac_data)pDec->pacInstance)->pFormatCtx->streams[pPackage->stream_index]->start_time;
|
||||
}
|
||||
|
||||
pts *= av_q2d(((lp_ac_data)pDec->pacInstance)->pFormatCtx->streams[pPackage->stream_index]->time_base);
|
||||
|
||||
pts = ac_sync_video(pPackage, pDec, pDecoder->pFrame, pts);
|
||||
pDec->timecode = pts;
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -795,11 +799,23 @@ int CALL_CONVT ac_drop_decode_package(lp_ac_package pPackage, lp_ac_decoder pDec
|
||||
int ac_drop_decode_video_package(lp_ac_package pPackage, lp_ac_video_decoder pDecoder, lp_ac_decoder pDec) {
|
||||
int finished;
|
||||
double pts;
|
||||
int len = 0;
|
||||
|
||||
avcodec_decode_video2(
|
||||
pDecoder->pCodecCtx, pDecoder->pFrame, &finished,
|
||||
&(((lp_ac_package_data)pPackage)->ffpackage));
|
||||
AVPacket pkt_tmp = ((lp_ac_package_data)pPackage)->ffpackage;
|
||||
|
||||
while (pkt_tmp.size > 0) {
|
||||
len = avcodec_decode_video2(
|
||||
pDecoder->pCodecCtx, pDecoder->pFrame,
|
||||
&finished, &pkt_tmp);
|
||||
|
||||
if (len < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pkt_tmp.size -= len;
|
||||
pkt_tmp.data += len;
|
||||
}
|
||||
|
||||
if (finished) {
|
||||
pts=0;
|
||||
//global_video_pkt_pts = ((lp_ac_package_data)pPackage)->ffpackage.pts;
|
||||
@@ -860,11 +876,12 @@ int CALL_CONVT ac_get_frame(lp_ac_instance pacInstance, lp_ac_decoder pDecoder)
|
||||
|
||||
lp_ac_package pPackage = ac_read_package(pacInstance);
|
||||
int done = 0;
|
||||
int pcount = 0;
|
||||
while(done == 0 && pPackage != NULL){
|
||||
if (((lp_ac_package_data)pPackage)->package.stream_index == pDecoder->stream_index){
|
||||
done = ac_decode_package(pPackage, pDecoder);
|
||||
ac_free_package(pPackage);
|
||||
|
||||
pcount++;
|
||||
if (done == 0)
|
||||
pPackage = ac_read_package(pacInstance);
|
||||
} else {
|
||||
@@ -876,7 +893,7 @@ int CALL_CONVT ac_get_frame(lp_ac_instance pacInstance, lp_ac_decoder pDecoder)
|
||||
if (done == 0)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
return pcount;
|
||||
}
|
||||
|
||||
int CALL_CONVT ac_skip_frames(lp_ac_instance pacInstance, lp_ac_decoder pDecoder, int num) {
|
||||
|
||||
@@ -258,8 +258,9 @@ namespace Vocaluxe.Lib.Video
|
||||
private bool _terminated = false;
|
||||
|
||||
private Thread _thread;
|
||||
AutoResetEvent EventDecode = new AutoResetEvent(false);
|
||||
//AutoResetEvent EventDecode = new AutoResetEvent(false);
|
||||
SFrameBuffer[] _FrameBuffer = new SFrameBuffer[5];
|
||||
private bool _NewFrame = false;
|
||||
Object MutexFramebuffer = new Object();
|
||||
Object MutexSyncSignals = new Object();
|
||||
|
||||
@@ -359,7 +360,7 @@ namespace Vocaluxe.Lib.Video
|
||||
|
||||
|
||||
UploadNewFrame(ref frame);
|
||||
EventDecode.Set();
|
||||
//EventDecode.Set();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -367,11 +368,11 @@ namespace Vocaluxe.Lib.Video
|
||||
{
|
||||
lock (MutexSyncSignals)
|
||||
{
|
||||
_SetTime = Time;
|
||||
VideoTime = _CurrentVideoTime;
|
||||
_SetTime = Time;
|
||||
}
|
||||
UploadNewFrame(ref frame);
|
||||
EventDecode.Set();
|
||||
VideoTime = _CurrentVideoTime;
|
||||
//EventDecode.Set();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -387,7 +388,7 @@ namespace Vocaluxe.Lib.Video
|
||||
_NoMoreFrames = false;
|
||||
_Finished = false;
|
||||
}
|
||||
EventDecode.Set();
|
||||
//EventDecode.Set();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -441,17 +442,18 @@ namespace Vocaluxe.Lib.Video
|
||||
|
||||
_BufferFull = false;
|
||||
_skip = false;
|
||||
EventDecode.Set();
|
||||
_NewFrame = false;
|
||||
//EventDecode.Set();
|
||||
}
|
||||
|
||||
private void Execute()
|
||||
{
|
||||
DoOpen();
|
||||
EventDecode.Set();
|
||||
//EventDecode.Set();
|
||||
|
||||
while (!_terminated)
|
||||
{
|
||||
if (EventDecode.WaitOne(10))
|
||||
//if (EventDecode.WaitOne(10))
|
||||
{
|
||||
lock (MutexSyncSignals)
|
||||
{
|
||||
@@ -468,11 +470,12 @@ namespace Vocaluxe.Lib.Video
|
||||
if (_skip)
|
||||
DoSkip();
|
||||
|
||||
if (!_BufferFull)
|
||||
if (!_NewFrame)
|
||||
DoDecode();
|
||||
|
||||
if (_BufferFull)
|
||||
Copy();
|
||||
if (_NewFrame)
|
||||
Copy();
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,7 +558,7 @@ namespace Vocaluxe.Lib.Video
|
||||
{
|
||||
const int FRAMEDROPCOUNT = 4;
|
||||
|
||||
if (!_FileOpened)
|
||||
if (!_FileOpened || _NewFrame)
|
||||
return;
|
||||
|
||||
if (_Paused || _NoMoreFrames || _BufferFull)
|
||||
@@ -641,12 +644,18 @@ namespace Vocaluxe.Lib.Video
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Copy();
|
||||
else
|
||||
{
|
||||
_NewFrame = true;
|
||||
Copy();
|
||||
}
|
||||
}
|
||||
|
||||
private void Copy()
|
||||
{
|
||||
if (!_NewFrame)
|
||||
return;
|
||||
|
||||
int num = -1;
|
||||
|
||||
lock (MutexFramebuffer)
|
||||
@@ -687,11 +696,13 @@ namespace Vocaluxe.Lib.Video
|
||||
|
||||
if (numfull < _FrameBuffer.Length)
|
||||
_BufferFull = false;
|
||||
|
||||
_NewFrame = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_BufferFull)
|
||||
EventDecode.Set();
|
||||
//if (!_BufferFull)
|
||||
// EventDecode.Set();
|
||||
}
|
||||
|
||||
private void UploadNewFrame(ref STexture frame)
|
||||
@@ -720,7 +731,7 @@ namespace Vocaluxe.Lib.Video
|
||||
_CurrentVideoTime = _FrameBuffer[num].time;
|
||||
}
|
||||
_Finished = false;
|
||||
EventDecode.Set();
|
||||
//EventDecode.Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -739,7 +750,7 @@ namespace Vocaluxe.Lib.Video
|
||||
{
|
||||
float td = _SetTime + _VideoSkipTime - _FrameBuffer[i].time;
|
||||
|
||||
if (td > _VideoTimeBase * 2)
|
||||
if (td > _VideoTimeBase * 2f)
|
||||
{
|
||||
_FrameBuffer[i].displayed = true;
|
||||
}
|
||||
@@ -754,6 +765,7 @@ namespace Vocaluxe.Lib.Video
|
||||
if (Result != -1)
|
||||
{
|
||||
_FrameBuffer[Result].displayed = true;
|
||||
_BufferFull = false;
|
||||
}
|
||||
|
||||
return Result;
|
||||
|
||||
Reference in new issue
Block a user