From ed931f6a22904d90de0dc36be0f5120eef772480 Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Fri, 2 Jun 2017 14:55:39 -0400
Subject: [PATCH] video: fix accel when setting is disabled

If Ring was compiled with acceleration, but is disabled in dring.yml,
the call would crash. This checks if the accel_ object isn't null
before checking if it has failed.

Change-Id: I098f573bd17271824fcfbdb60d783af085ef19be
Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 src/media/media_decoder.cpp | 8 +++++---
 src/media/video/accel.cpp   | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/media/media_decoder.cpp b/src/media/media_decoder.cpp
index 0512111a5c..0b704f8782 100644
--- a/src/media/media_decoder.cpp
+++ b/src/media/media_decoder.cpp
@@ -312,6 +312,8 @@ int MediaDecoder::setupFromVideoData()
     if (enableAccel_) {
         accel_ = video::makeHardwareAccel(decoderCtx_);
         decoderCtx_->opaque = accel_.get();
+    } else {
+        RING_WARN("Hardware accelerated decoding disabled by user preference");
     }
 #endif // RING_ACCEL
 
@@ -365,7 +367,7 @@ MediaDecoder::decode(VideoFrame& result)
     ret = avcodec_send_packet(decoderCtx_, &inpacket);
     if (ret < 0) {
 #ifdef RING_ACCEL
-        if (accel_->hasFailed())
+        if (accel_ && accel_->hasFailed())
             return Status::RestartRequired;
 #endif
         return ret == AVERROR_EOF ? Status::Success : Status::DecodeError;
@@ -373,7 +375,7 @@ MediaDecoder::decode(VideoFrame& result)
     ret = avcodec_receive_frame(decoderCtx_, frame);
     if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
 #ifdef RING_ACCEL
-        if (accel_->hasFailed())
+        if (accel_ && accel_->hasFailed())
             return Status::RestartRequired;
 #endif
         return Status::DecodeError;
@@ -385,7 +387,7 @@ MediaDecoder::decode(VideoFrame& result)
                                     &frameFinished, &inpacket);
     if (ret <= 0) {
 #ifdef RING_ACCEL
-        if (accel_->hasFailed())
+        if (accel_ && accel_->hasFailed())
             return Status::RestartRequired;
 #endif
         return Status::DecodeError;
diff --git a/src/media/video/accel.cpp b/src/media/video/accel.cpp
index 5bd9dc4985..e17f49f776 100644
--- a/src/media/video/accel.cpp
+++ b/src/media/video/accel.cpp
@@ -225,7 +225,7 @@ makeHardwareAccel(AVCodecContext* codecCtx)
                     codecCtx->get_buffer2 = allocateBufferCb;
                     codecCtx->thread_safe_callbacks = 1;
                     codecCtx->thread_count = 1;
-                    RING_DBG("Succesfully set up '%s' acceleration", accel->name().c_str());
+                    RING_DBG("Attempting to use '%s' hardware acceleration", accel->name().c_str());
                     return accel;
                 }
             }
-- 
GitLab