[vdr-plugin-softhddevice] 01/03: Imported Upstream version 0.6.0+git20141124

Tobias Grimm tiber-guest at moszumanska.debian.org
Mon Nov 24 23:44:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

tiber-guest pushed a commit to branch master
in repository vdr-plugin-softhddevice.

commit 0507f688050360fc136567bff8ebd4e06ea7c0c2
Author: etobi <git at e-tobi.net>
Date:   Tue Nov 25 00:42:01 2014 +0100

    Imported Upstream version 0.6.0+git20141124
---
 ChangeLog   |  21 ++++++++-
 audio.c     |  29 +++++++++---
 codec.c     |  40 +++++++++++++----
 softhddev.c |   2 +-
 video.c     | 146 ++++++++++++++++++++++++++++++++++++------------------------
 5 files changed, 163 insertions(+), 75 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a611b32..79bf45a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,25 @@
+User Antti Sepp�l�
+Date: Thu Oct 16 14:15:15 CEST 2014
+
+    Corrected black surface for va-api.
+
+User johns
+Date: Thu Oct 16 14:05:17 CEST 2014
+
+    Newer va-api intel drivers support PutImage.
+    Use more portable fork for vfork.
+    Fix crash with VA-API vdpau backend.
+
+User mini73
+Date: Sat Oct 11 16:53:18 CEST 2014
+
+    Fix bug: random rubbish at the end of letter.
+
 User johns
-Date:
+Date: Tue Sep 23 12:36:39 CEST 2014
 
+    Fix audio thread close race condition.
+    Support ffmpeg new AVFrame API in the audio codec.
     Config for automatic AES parameters.
     Use GCC built-in functions for atomic operations.
 
diff --git a/audio.c b/audio.c
index 6ca3df1..a9da207 100644
--- a/audio.c
+++ b/audio.c
@@ -149,6 +149,7 @@ static int AudioBufferTime = 336;	///< audio buffer time in ms
 static pthread_t AudioThread;		///< audio play thread
 static pthread_mutex_t AudioMutex;	///< audio condition mutex
 static pthread_cond_t AudioStartCond;	///< condition variable
+static char AudioThreadStop;		///< stop audio thread
 #else
 static const int AudioThread;		///< dummy audio thread
 #endif
@@ -942,7 +943,6 @@ static int AlsaThread(void)
 	return -1;
     }
     for (;;) {
-	pthread_testcancel();
 	if (AudioPaused) {
 	    return 1;
 	}
@@ -1216,7 +1216,8 @@ static int AlsaSetup(int *freq, int *channels, int passthrough)
 	snd_pcm_t *handle;
 
 	handle = AlsaPCMHandle;
-	// FIXME: need lock
+	// no lock needed, thread exit in main loop only
+	//Debug(3, "audio: %s [\n", __FUNCTION__);
 	AlsaPCMHandle = NULL;		// other threads should check handle
 	snd_pcm_close(handle);
 	if (AudioAlsaCloseOpenDelay) {
@@ -1227,6 +1228,7 @@ static int AlsaSetup(int *freq, int *channels, int passthrough)
 	    return -1;
 	}
 	AlsaPCMHandle = handle;
+	//Debug(3, "audio: %s ]\n", __FUNCTION__);
     }
 
     for (;;) {
@@ -1548,7 +1550,6 @@ static int OssThread(void)
     for (;;) {
 	struct pollfd fds[1];
 
-	pthread_testcancel();
 	if (AudioPaused) {
 	    return 1;
 	}
@@ -2050,6 +2051,12 @@ static void *AudioPlayHandlerThread(void *dummy)
 {
     Debug(3, "audio: play thread started\n");
     for (;;) {
+	// check if we should stop the thread
+	if (AudioThreadStop) {
+	    Debug(3, "audio: play thread stopped\n");
+	    return PTHREAD_CANCELED;
+	}
+
 	Debug(3, "audio: wait on start condition\n");
 	pthread_mutex_lock(&AudioMutex);
 	AudioRunning = 0;
@@ -2072,6 +2079,11 @@ static void *AudioPlayHandlerThread(void *dummy)
 	    int err;
 	    int i;
 
+	    // check if we should stop the thread
+	    if (AudioThreadStop) {
+		Debug(3, "audio: play thread stopped\n");
+		return PTHREAD_CANCELED;
+	    }
 	    // look if there is a flush command in the queue
 	    flush = 0;
 	    filled = atomic_read(&AudioRingFilled);
@@ -2156,6 +2168,7 @@ static void *AudioPlayHandlerThread(void *dummy)
 */
 static void AudioInitThread(void)
 {
+    AudioThreadStop = 0;
     pthread_mutex_init(&AudioMutex, NULL);
     pthread_cond_init(&AudioStartCond, NULL);
     pthread_create(&AudioThread, NULL, AudioPlayHandlerThread, NULL);
@@ -2169,10 +2182,12 @@ static void AudioExitThread(void)
 {
     void *retval;
 
+    Debug(3, "audio: %s\n", __FUNCTION__);
+
     if (AudioThread) {
-	if (pthread_cancel(AudioThread)) {
-	    Error(_("audio: can't queue cancel play thread\n"));
-	}
+	AudioThreadStop = 1;
+	AudioRunning = 1;		// wakeup thread, if needed
+	pthread_cond_signal(&AudioStartCond);
 	if (pthread_join(AudioThread, &retval) || retval != PTHREAD_CANCELED) {
 	    Error(_("audio: can't cancel play thread\n"));
 	}
@@ -2994,6 +3009,8 @@ void AudioExit(void)
 {
     const AudioModule *module;
 
+    Debug(3, "audio: %s\n", __FUNCTION__);
+
 #ifdef USE_AUDIO_THREAD
     if (AudioUsedModule->Thread) {	// supports threads
 	AudioExitThread();
diff --git a/codec.c b/codec.c
index 03ba028..d089a84 100644
--- a/codec.c
+++ b/codec.c
@@ -681,6 +681,10 @@ struct _audio_decoder_
     int HwSampleRate;			///< hw sample rate
     int HwChannels;			///< hw channels
 
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58,28,1)
+    AVFrame *Frame;			///< decoded audio frame buffer
+#endif
+
 #if !defined(USE_SWRESAMPLE) && !defined(USE_AVRESAMPLE)
     ReSampleContext *ReSample;		///< old resampling context
 #endif
@@ -757,6 +761,11 @@ AudioDecoder *CodecAudioNewDecoder(void)
     if (!(audio_decoder = calloc(1, sizeof(*audio_decoder)))) {
 	Fatal(_("codec: can't allocate audio decoder\n"));
     }
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58,28,1)
+    if (!(audio_decoder->Frame = av_frame_alloc())) {
+	Fatal(_("codec: can't allocate audio decoder frame buffer\n"));
+    }
+#endif
 
     return audio_decoder;
 }
@@ -768,6 +777,9 @@ AudioDecoder *CodecAudioNewDecoder(void)
 */
 void CodecAudioDelDecoder(AudioDecoder * decoder)
 {
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58,28,1)
+    av_frame_free(&decoder->Frame);	// callee does checks
+#endif
     free(decoder);
 }
 
@@ -1790,18 +1802,30 @@ static void CodecAudioUpdateFormat(AudioDecoder * audio_decoder)
 void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
 {
     AVCodecContext *audio_ctx;
-    AVFrame frame;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,28,1)
+    AVFrame frame[1];
+#else
+    AVFrame *frame;
+#endif
     int got_frame;
     int n;
 
     audio_ctx = audio_decoder->AudioCtx;
 
     // FIXME: don't need to decode pass-through codecs
-    // libav needs memset, frame.data[0] = NULL;
-    memset(&frame, 0, sizeof(frame));
+
+    // new AVFrame API
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,28,1)
+    avcodec_get_frame_defaults(frame);
+#else
+    frame = audio_decoder->Frame;
+    av_frame_unref(frame);
+#endif
+
     got_frame = 0;
-    n = avcodec_decode_audio4(audio_ctx, &frame, &got_frame,
+    n = avcodec_decode_audio4(audio_ctx, frame, &got_frame,
 	(AVPacket *) avpkt);
+
     if (n != avpkt->size) {
 	if (n == AVERROR(EAGAIN)) {
 	    Error(_("codec/audio: latm\n"));
@@ -1843,7 +1867,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
 
 	data_sz =
 	    av_samples_get_buffer_size(&plane_sz, audio_ctx->channels,
-	    frame.nb_samples, audio_ctx->sample_fmt, 1);
+	    frame->nb_samples, audio_ctx->sample_fmt, 1);
 	fprintf(stderr, "codec/audio: sample_fmt %s\n",
 	    av_get_sample_fmt_name(audio_ctx->sample_fmt));
 	av_get_channel_layout_string(strbuf, 32, audio_ctx->channels,
@@ -1851,7 +1875,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
 	fprintf(stderr, "codec/audio: layout %s\n", strbuf);
 	fprintf(stderr,
 	    "codec/audio: channels %d samples %d plane %d data %d\n",
-	    audio_ctx->channels, frame.nb_samples, plane_sz, data_sz);
+	    audio_ctx->channels, frame->nb_samples, plane_sz, data_sz);
     }
 #ifdef USE_SWRESAMPLE
     if (audio_decoder->Resample) {
@@ -1861,7 +1885,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
 	out[0] = outbuf;
 	n = swr_convert(audio_decoder->Resample, out,
 	    sizeof(outbuf) / (2 * audio_decoder->HwChannels),
-	    (const uint8_t **)frame.extended_data, frame.nb_samples);
+	    (const uint8_t **)frame->extended_data, frame->nb_samples);
 	if (n > 0) {
 	    if (!(audio_decoder->Passthrough & CodecPCM)) {
 		CodecReorderAudioFrame((int16_t *) outbuf,
@@ -1882,7 +1906,7 @@ void CodecAudioDecode(AudioDecoder * audio_decoder, const AVPacket * avpkt)
 	out[0] = outbuf;
 	n = avresample_convert(audio_decoder->Resample, out, 0,
 	    sizeof(outbuf) / (2 * audio_decoder->HwChannels),
-	    (uint8_t **) frame.extended_data, 0, frame.nb_samples);
+	    (uint8_t **) frame->extended_data, 0, frame->nb_samples);
 	// FIXME: set out_linesize, in_linesize correct
 	if (n > 0) {
 	    if (!(audio_decoder->Passthrough & CodecPCM)) {
diff --git a/softhddev.c b/softhddev.c
index 1759109..d0e32ee 100644
--- a/softhddev.c
+++ b/softhddev.c
@@ -3092,7 +3092,7 @@ static void StartXServer(void)
     Debug(3, "x-setup: Starting X server '%s' '%s'\n", args[0],
 	X11ServerArguments);
     //	fork
-    if ((pid = vfork())) {		// parent
+    if ((pid = fork())) {		// parent
 
 	X11ServerPid = pid;
 	Debug(3, "x-setup: Started x-server pid=%d\n", X11ServerPid);
diff --git a/video.c b/video.c
index a5b3a5a..7f47f5e 100644
--- a/video.c
+++ b/video.c
@@ -1446,7 +1446,6 @@ static void AutoCropDetect(AutoCropCtx * autocrop, int width, int height,
 static char VaapiBuggyXvBA;		///< fix xvba-video bugs
 static char VaapiBuggyVdpau;		///< fix libva-driver-vdpau bugs
 static char VaapiBuggyIntel;		///< fix libva-driver-intel bugs
-static char VaapiNewIntel;		///< new libva-driver-intel driver
 
 static VADisplay *VaDisplay;		///< VA-API display
 
@@ -2000,9 +1999,13 @@ static VaapiDecoder *VaapiNewHwDecoder(VideoStream * stream)
 
     decoder->PTS = AV_NOPTS_VALUE;
 
-    // get/put still not working
-    //decoder->GetPutImage = !VaapiBuggyIntel || VaapiNewIntel;
+    // old va-api intel driver didn't supported get/put-image.
+#if VA_CHECK_VERSION(0,33,99)
+    // FIXME: not the exact version with support
+    decoder->GetPutImage = 1;
+#else
     decoder->GetPutImage = !VaapiBuggyIntel;
+#endif
 
     VaapiDecoders[VaapiDecoderN++] = decoder;
 
@@ -2346,9 +2349,6 @@ static int VaapiInit(const char *display_name)
     if (strstr(s, "Intel i965")) {
 	VaapiBuggyIntel = 1;
     }
-    if (strstr(s, "Intel i965 driver - 1.0.16.")) {
-	VaapiNewIntel = 1;
-    }
     //
     //	check which attributes are supported
     //
@@ -2380,15 +2380,17 @@ static int VaapiInit(const char *display_name)
 	int entrypoint_n;
 	int i;
 
-	vaQueryConfigEntrypoints(VaDisplay, VAProfileNone, entrypoints,
-	    &entrypoint_n);
-
 	VaapiVideoProcessing = 0;
-	for (i = 0; i < entrypoint_n; i++) {
-	    if (entrypoints[i] == VAEntrypointVideoProc) {
-		Info("video/vaapi: supports video processing\n");
-		VaapiVideoProcessing = 1;
-		break;
+	if (!vaQueryConfigEntrypoints(VaDisplay, VAProfileNone, entrypoints,
+		&entrypoint_n)) {
+
+	    for (i = 0; i < entrypoint_n; i++) {
+		fprintf(stderr, "oops %d\n", i);
+		if (entrypoints[i] == VAEntrypointVideoProc) {
+		    Info("video/vaapi: supports video processing\n");
+		    VaapiVideoProcessing = 1;
+		    break;
+		}
 	    }
 	}
     }
@@ -3553,66 +3555,85 @@ static void VaapiBlackSurface(VaapiDecoder * decoder)
     }
 
     if (decoder->BlackSurface == VA_INVALID_ID) {
-	if (vaCreateSurfaces(decoder->VaDisplay, VA_RT_FORMAT_YUV420,
-		VideoWindowWidth, VideoWindowHeight, &decoder->BlackSurface, 1,
-		NULL, 0) != VA_STATUS_SUCCESS) {
-	    Error(_("video/vaapi: can't create a surface\n"));
+	uint8_t *va_image_data;
+	unsigned u;
+
+	status =
+	    vaCreateSurfaces(decoder->VaDisplay, VA_RT_FORMAT_YUV420,
+	    VideoWindowWidth, VideoWindowHeight, &decoder->BlackSurface, 1,
+	    NULL, 0);
+	if (status != VA_STATUS_SUCCESS) {
+	    Error(_("video/vaapi: can't create a surface: %s\n"),
+		vaErrorStr(status));
 	    return;
 	}
 	// full sized surface, no difference unscaled/scaled osd
-	if (vaAssociateSubpicture(decoder->VaDisplay, VaOsdSubpicture,
-		&decoder->BlackSurface, 1, 0, 0, VaOsdImage.width,
-		VaOsdImage.height, 0, 0, VideoWindowWidth, VideoWindowHeight,
-		0) != VA_STATUS_SUCCESS) {
-	    Error(_("video/vaapi: can't associate subpicture\n"));
+	status =
+	    vaAssociateSubpicture(decoder->VaDisplay, VaOsdSubpicture,
+	    &decoder->BlackSurface, 1, 0, 0, VaOsdImage.width,
+	    VaOsdImage.height, 0, 0, VideoWindowWidth, VideoWindowHeight, 0);
+	if (status != VA_STATUS_SUCCESS) {
+	    Error(_("video/vaapi: can't associate subpicture: %s\n"),
+		vaErrorStr(status));
 	}
 	Debug(3, "video/vaapi: associate %08x\n", decoder->BlackSurface);
-	// FIXME: check if intel forgets this also
 
-	if (0 && decoder->Image->image_id == VA_INVALID_ID) {
+	if (decoder->Image->image_id == VA_INVALID_ID) {
 	    VAImageFormat format[1];
-	    void *va_image_data;
-	    int i;
 
-	    printf("No image\n");
 	    VaapiFindImageFormat(decoder, PIX_FMT_NV12, format);
-	    if ((status =
-		    vaDeriveImage(decoder->VaDisplay, decoder->BlackSurface,
-			decoder->Image)) != VA_STATUS_SUCCESS) {
-		Error(_("video/vaapi: vaDeriveImage failed %d\n"), status);
-		if (vaCreateImage(VaDisplay, format, VideoWindowWidth,
-			VideoWindowHeight,
-			decoder->Image) != VA_STATUS_SUCCESS) {
-		    Error(_("video/vaapi: can't create image!\n"));
-		}
-	    }
-	    if (vaMapBuffer(VaDisplay, decoder->Image->buf, &va_image_data)
-		!= VA_STATUS_SUCCESS) {
-		Error(_("video/vaapi: can't map the image!\n"));
+	    status =
+		vaCreateImage(VaDisplay, format, VideoWindowWidth,
+		VideoWindowHeight, decoder->Image);
+	    if (status != VA_STATUS_SUCCESS) {
+		Error(_("video/vaapi: can't create image: %s\n"),
+		    vaErrorStr(status));
+		return;
 	    }
+	}
 
-	    for (i = 0; (unsigned)i < decoder->Image->data_size; i += 2) {
-		((uint8_t *) va_image_data)[i + 0] = 0xFF;
-		((uint8_t *) va_image_data)[i + 1] = 0xFF;
-	    }
+	status =
+	    vaMapBuffer(VaDisplay, decoder->Image->buf,
+	    (void **)&va_image_data);
+	if (status != VA_STATUS_SUCCESS) {
+	    Error(_("video/vaapi: can't map the image: %s\n"),
+		vaErrorStr(status));
+	    return;
+	}
 
-	    if (vaUnmapBuffer(VaDisplay,
-		    decoder->Image->buf) != VA_STATUS_SUCCESS) {
-		Error(_("video/vaapi: can't unmap the image!\n"));
-	    }
-	    if (vaDestroyImage(VaDisplay,
-		    decoder->Image->image_id) != VA_STATUS_SUCCESS) {
-		Error(_("video/vaapi: can't destroy image!\n"));
+	for (u = 0; u < decoder->Image->data_size; ++u) {
+	    if (u < decoder->Image->offsets[1]) {
+		va_image_data[u] = 0x00;	// Y
+	    } else if (u % 2 == 0) {
+		va_image_data[u] = 0x80;	// U
+	    } else {
+#ifdef DEBUG
+		// make black surface visible
+		va_image_data[u] = 0xFF;	// V
+#else
+		va_image_data[u] = 0x80;	// V
+#endif
 	    }
 	}
-	// FIXME: intel didn't support put image.
-	if (0
-	    && vaPutImage(VaDisplay, decoder->BlackSurface,
+
+	if (vaUnmapBuffer(VaDisplay, decoder->Image->buf) != VA_STATUS_SUCCESS) {
+	    Error(_("video/vaapi: can't unmap the image!\n"));
+	}
+
+	if (decoder->GetPutImage) {
+	    status =
+		vaPutImage(VaDisplay, decoder->BlackSurface,
 		decoder->Image->image_id, 0, 0, VideoWindowWidth,
-		VideoWindowHeight, 0, 0, VideoWindowWidth, VideoWindowHeight)
-	    != VA_STATUS_SUCCESS) {
-	    Error(_("video/vaapi: can't put image!\n"));
+		VideoWindowHeight, 0, 0, VideoWindowWidth, VideoWindowHeight);
+	    if (status != VA_STATUS_SUCCESS) {
+		Error(_("video/vaapi: can't put image!\n"));
+	    }
+	} else {
+	    // FIXME: PutImage isn't always supported
+	    Debug(3,
+		"video/vaapi: put image not supported, alternative path not written\n");
 	}
+
 #ifdef DEBUG
 	start = GetMsTicks();
 #endif
@@ -9736,6 +9757,7 @@ static void VideoEvent(void)
     const char *keynam;
     char buf[64];
     char letter[64];
+    int letter_len;
     uint32_t values[1];
 
     VideoThreadLock();
@@ -9775,8 +9797,14 @@ static void VideoEvent(void)
 	    break;
 	case KeyPress:
 	    VideoThreadLock();
-	    XLookupString(&event.xkey, letter, sizeof(letter), &keysym, NULL);
+	    letter_len =
+		XLookupString(&event.xkey, letter, sizeof(letter) - 1, &keysym,
+		NULL);
 	    VideoThreadUnlock();
+	    if (letter_len < 0) {
+		letter_len = 0;
+	    }
+	    letter[letter_len] = '\0';
 	    if (keysym == NoSymbol) {
 		Warning(_("video/event: No symbol for %d\n"),
 		    event.xkey.keycode);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-vdr-dvb/vdr-plugin-softhddevice.git



More information about the pkg-vdr-dvb-changes mailing list