diff mbox

[FFmpeg-devel,v4,2/3] lavc/libdavs2.c: fix decoder info level setting

Message ID 1563769418-18983-3-git-send-email-hwrenx@126.com
State Superseded
Headers show

Commit Message

hwren July 22, 2019, 4:23 a.m. UTC
Mapping log level from av_log_level to davs3_log_level_e:

[AV_LOG_QUIET, AV_LOG_ERROR]   => DAVS2_LOG_ERROR
[AV_LOG_WARNING]               => DAVS2_LOG_WARNING
[AV_LOG_INFO]                  => DAVS2_LOG_INFO
[AV_LOG_VERBOSE, AV_LOG_TRACE] => DAVS2_LOG_DEBUG

in values:

[-8, 16] => 3
[17, 24] => 2
[25, 32] => 1
[33, 56] => 0

After clip into [AV_LOG_FATAL + 1, AV_LOG_VERBOSE]([9, 40]), davs2 log
level can be expressed as (4-(((av_log_level)-1)>>3)).

Signed-off-by: hwrenx <hwrenx@126.com>
---
 libavcodec/libdavs2.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Reimar Döffinger July 22, 2019, 5:03 a.m. UTC | #1
On 22.07.2019, at 06:23, hwrenx <hwrenx@126.com> wrote:

> Mapping log level from av_log_level to davs3_log_level_e:
> 
> [AV_LOG_QUIET, AV_LOG_ERROR]   => DAVS2_LOG_ERROR
> [AV_LOG_WARNING]               => DAVS2_LOG_WARNING
> [AV_LOG_INFO]                  => DAVS2_LOG_INFO
> [AV_LOG_VERBOSE, AV_LOG_TRACE] => DAVS2_LOG_DEBUG
> 
> in values:
> 
> [-8, 16] => 3
> [17, 24] => 2
> [25, 32] => 1
> [33, 56] => 0
> 
> After clip into [AV_LOG_FATAL + 1, AV_LOG_VERBOSE]([9, 40]), davs2 log
> level can be expressed as (4-(((av_log_level)-1)>>3)).

The AV_LOG_... values might change at some point.
I'd suggest using a couple of ifs instead of trying something "clever" like this.
hwren July 22, 2019, 7:13 a.m. UTC | #2
Version 5:
1. Using ifs for log level instead of expressions.

--------
Version 4:
1. Change info level setting.
2. Remove `Decoder not found` condition.

--------
The previous version 2 patches were deprecated for using
pointer to itself can be unsafe when release frames.

This patch set is mainly about avoiding using memcpy when fetching
frame data, and fixed missing start codes which may cause error
packetization sometime. Default info level of libdavs2 was changed
because we found debug info is useless in most of the time.
hwrenx (3):
  lavc/avs2_parser.c: fix missing start code
  lavc/libdavs2.c: fix decoder info level setting
  lavc/libdavs2.c: reduce memcpy

 libavcodec/avs2_parser.c |  4 ++-
 libavcodec/libdavs2.c    | 69 +++++++++++++++++++++++++++++++-----------------
 2 files changed, 48 insertions(+), 25 deletions(-)

The performance comparison is like following:

[Platform]
  Intel® Core™ i7-8700k CPU @ 3.70GHz × 6 / 16GiB
[Command]
  ffmpeg -i test.avs2 -vsync 0 -f null -
[Stream]
  7680x4320 yuv420p Random Access
[Original version]
  frame= 2669 fps= 23 q=-0.0 Lsize=N/A time=00:00:53.44 bitrate=N/A speed=0.465x
[Optimized version]
  frame= 2669 fps= 42 q=-0.0 Lsize=N/A time=00:00:53.44 bitrate=N/A speed=0.836x
diff mbox

Patch

diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c
index 218f3ec..79b3e4f 100644
--- a/libavcodec/libdavs2.c
+++ b/libavcodec/libdavs2.c
@@ -25,6 +25,9 @@ 
 #include "avcodec.h"
 #include "davs2.h"
 
+/* map log_level from 16/24/32/40 to 3/2/1/0 */
+#define DAVS2_GET_LEVEL(x) (4-(((x)-1)>>3))
+
 typedef struct DAVS2Context {
     void *decoder;
 
@@ -41,10 +44,14 @@  static av_cold int davs2_init(AVCodecContext *avctx)
 {
     DAVS2Context *cad = avctx->priv_data;
     int cpu_flags = av_get_cpu_flags();
+    int log_level = av_log_get_level();
+
+    /* fix for davs2 level range */
+    log_level = av_clip(log_level, AV_LOG_FATAL + 1, AV_LOG_VERBOSE);
 
     /* init the decoder */
     cad->param.threads      = avctx->thread_count;
-    cad->param.info_level   = 0;
+    cad->param.info_level   = DAVS2_GET_LEVEL(log_level);
     cad->param.disable_avx  = !(cpu_flags & AV_CPU_FLAG_AVX &&
                                 cpu_flags & AV_CPU_FLAG_AVX2);
     cad->decoder            = davs2_decoder_open(&cad->param);