[x265] [PATCH] api: 'x265_get_ref_frame_list' to get forward and backward refrence list

praveen at multicorewareinc.com praveen at multicorewareinc.com
Fri Nov 3 11:51:47 CET 2017


# HG changeset patch
# User Praveen Tiwari <praveen at multicorewareinc.com>
# Date 1509446629 -19800
#      Tue Oct 31 16:13:49 2017 +0530
# Node ID 6ad93877ffe19cd6cf285f0cc8189f41dce606b8
# Parent  de91aae2db5353e4e548d002e2dce530a6c8078d
api: 'x265_get_ref_frame_list' to get forward and backward refrence list

diff -r de91aae2db53 -r 6ad93877ffe1 doc/reST/api.rst
--- a/doc/reST/api.rst	Tue Oct 31 13:57:37 2017 +0530
+++ b/doc/reST/api.rst	Tue Oct 31 16:13:49 2017 +0530
@@ -201,6 +201,13 @@
      *     This API must be called after(poc >= lookaheadDepth + bframes + 2) condition check. */
      int x265_get_slicetype_poc_and_scenecut(x265_encoder *encoder, int *slicetype, int *poc, int* sceneCut);
 
+**x265_get_ref_frame_list()** may be used to fetch forward and backward refrence list::
+
+    /* x265_get_ref_frame_list:
+     *     returns negative on error, 0 when access unit were output.
+     *     This API must be called after(poc >= lookaheadDepth + bframes + 2) condition check */
+     int x265_get_ref_frame_list(x265_encoder *encoder, x265_picyuv**, x265_picyuv**, int, int);
+ 
 **x265_encoder_ctu_info**
        /* x265_encoder_ctu_info:
         *    Copy CTU information such as ctu address and ctu partition structure of all
diff -r de91aae2db53 -r 6ad93877ffe1 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/CMakeLists.txt	Tue Oct 31 16:13:49 2017 +0530
@@ -29,7 +29,7 @@
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 137)
+set(X265_BUILD 138)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r de91aae2db53 -r 6ad93877ffe1 source/common/frame.h
--- a/source/common/frame.h	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/common/frame.h	Tue Oct 31 16:13:49 2017 +0530
@@ -98,6 +98,7 @@
 
     float*                 m_quantOffsets;       // points to quantOffsets in x265_picture
     x265_sei               m_userSEI;
+    Event                  m_reconEncoded;
 
     /* Frame Parallelism - notification between FrameEncoders of available motion reference rows */
     ThreadSafeInteger*     m_reconRowFlag;       // flag of CTU rows completely reconstructed and extended for motion reference
diff -r de91aae2db53 -r 6ad93877ffe1 source/common/picyuv.h
--- a/source/common/picyuv.h	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/common/picyuv.h	Tue Oct 31 16:13:49 2017 +0530
@@ -27,6 +27,7 @@
 #include "common.h"
 #include "md5.h"
 #include "x265.h"
+struct x265_picyuv {};
 
 namespace X265_NS {
 // private namespace
@@ -34,7 +35,7 @@
 class ShortYuv;
 struct SPS;
 
-class PicYuv
+class PicYuv : public x265_picyuv
 {
 public:
 
diff -r de91aae2db53 -r 6ad93877ffe1 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/encoder/api.cpp	Tue Oct 31 16:13:49 2017 +0530
@@ -350,6 +350,15 @@
     return -1;
 }
 
+int x265_get_ref_frame_list(x265_encoder *enc, x265_picyuv** l0, x265_picyuv** l1, int sliceType, int poc)
+{
+    if (!enc)
+        return -1;
+
+    Encoder *encoder = static_cast<Encoder*>(enc);
+    return encoder->getRefFrameList((PicYuv**)l0, (PicYuv**)l1, sliceType, poc);
+}
+
 void x265_cleanup(void)
 {
     BitCost::destroy();
@@ -424,6 +433,7 @@
     &x265_encoder_intra_refresh,
     &x265_encoder_ctu_info,
     &x265_get_slicetype_poc_and_scenecut,
+    &x265_get_ref_frame_list,
 };
 
 typedef const x265_api* (*api_get_func)(int bitDepth);
diff -r de91aae2db53 -r 6ad93877ffe1 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/encoder/encoder.cpp	Tue Oct 31 16:13:49 2017 +0530
@@ -446,6 +446,47 @@
     return 0;
 }
 
+int Encoder::getRefFrameList(PicYuv** l0, PicYuv** l1, int sliceType, int poc)
+{
+    if (!(IS_X265_TYPE_I(sliceType)))
+    {
+        Frame *framePtr = m_dpb->m_picList.getPOC(poc);
+        if (framePtr != NULL)
+        {
+            for (int j = 0; j < framePtr->m_encData->m_slice->m_numRefIdx[0]; j++)    // check only for --ref=n number of frames.
+            {
+                if (framePtr->m_encData->m_slice->m_refFrameList[0][j] && framePtr->m_encData->m_slice->m_refFrameList[0][j]->m_reconPic != NULL)
+                {
+                    int l0POC = framePtr->m_encData->m_slice->m_refFrameList[0][j]->m_poc;
+                    Frame* l0Fp = m_dpb->m_picList.getPOC(l0POC);
+                    if (l0Fp->m_reconPic->m_picOrg[0] == NULL)
+                        l0Fp->m_reconEncoded.wait(); /* If recon is not ready, current frame encoder need to wait. */
+                    l0[j] = l0Fp->m_reconPic;
+                }
+            }
+            for (int j = 0; j < framePtr->m_encData->m_slice->m_numRefIdx[1]; j++)    // check only for --ref=n number of frames.
+            {
+                if (framePtr->m_encData->m_slice->m_refFrameList[1][j] && framePtr->m_encData->m_slice->m_refFrameList[1][j]->m_reconPic != NULL)
+                {
+                    int l1POC = framePtr->m_encData->m_slice->m_refFrameList[1][j]->m_poc;
+                    Frame* l1Fp = m_dpb->m_picList.getPOC(l1POC);
+                    if (l1Fp->m_reconPic->m_picOrg[0] == NULL)
+                        l1Fp->m_reconEncoded.wait(); /* If recon is not ready, current frame encoder need to wait. */
+                    l1[j] = l1Fp->m_reconPic;
+                }
+            }
+        }
+        else
+            x265_log(NULL, X265_LOG_WARNING, "Refrence List is not in piclist\n");
+    }
+    else
+    {
+        x265_log(NULL, X265_LOG_ERROR, "I frames does not have a refrence List\n");
+        return -1;
+    }
+    return 0;
+}
+
 void Encoder::destroy()
 {
 #if ENABLE_HDR10_PLUS
diff -r de91aae2db53 -r 6ad93877ffe1 source/encoder/encoder.h
--- a/source/encoder/encoder.h	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/encoder/encoder.h	Tue Oct 31 16:13:49 2017 +0530
@@ -207,6 +207,8 @@
 
     int copySlicetypePocAndSceneCut(int *slicetype, int *poc, int *sceneCut);
 
+    int getRefFrameList(PicYuv** l0, PicYuv** l1, int sliceType, int poc);
+
     void getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs);
 
     void fetchStats(x265_stats* stats, size_t statsSizeBytes);
diff -r de91aae2db53 -r 6ad93877ffe1 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/encoder/frameencoder.cpp	Tue Oct 31 16:13:49 2017 +0530
@@ -337,6 +337,8 @@
         }
         compressFrame();
         m_done.trigger(); /* FrameEncoder::getEncodedPicture() blocks for this event */
+        if (m_frame != NULL)
+            m_frame->m_reconEncoded.trigger();
         m_enable.wait();
     }
 }
diff -r de91aae2db53 -r 6ad93877ffe1 source/x265.h
--- a/source/x265.h	Tue Oct 31 13:57:37 2017 +0530
+++ b/source/x265.h	Tue Oct 31 16:13:49 2017 +0530
@@ -35,6 +35,10 @@
  *      opaque handler for encoder */
 typedef struct x265_encoder x265_encoder;
 
+/* x265_picyuv:
+ *      opaque handler for PicYuv */
+typedef struct x265_picyuv x265_picyuv;
+
 /* Application developers planning to link against a shared library version of
  * libx265 from a Microsoft Visual Studio or similar development environment
  * will need to define X265_API_IMPORTS before including this header.
@@ -1712,6 +1716,11 @@
  *     This API must be called after(poc >= lookaheadDepth + bframes + 2) condition check */
 int x265_get_slicetype_poc_and_scenecut(x265_encoder *encoder, int *slicetype, int *poc, int* sceneCut);
 
+/* x265_get_ref_frame_list:
+ *     returns negative on error, 0 when access unit were output.
+ *     This API must be called after(poc >= lookaheadDepth + bframes + 2) condition check */
+int x265_get_ref_frame_list(x265_encoder *encoder, x265_picyuv**, x265_picyuv**, int, int);
+
 void x265_cleanup(void);
 
 #define X265_MAJOR_VERSION 1
@@ -1760,6 +1769,7 @@
     int           (*encoder_intra_refresh)(x265_encoder*);
     int           (*encoder_ctu_info)(x265_encoder*, int, x265_ctu_info_t**);
     int           (*x265_get_slicetype_poc_and_scenecut)(x265_encoder*, int*, int*, int*);
+    int           (*x265_get_ref_frame_list)(x265_encoder*, x265_picyuv**, x265_picyuv**, int, int);
     /* add new pointers to the end, or increment X265_MAJOR_VERSION */
 } x265_api;
 


More information about the x265-devel mailing list