changeset 11897:6ad93877ffe1 draft

api: 'x265_get_ref_frame_list' to get forward and backward refrence list
author Praveen Tiwari <praveen@multicorewareinc.com>
date Tue, 31 Oct 2017 16:13:49 +0530
parents de91aae2db53
children 7b7355a8e587
files doc/reST/api.rst source/CMakeLists.txt source/common/frame.h source/common/picyuv.h source/encoder/api.cpp source/encoder/encoder.cpp source/encoder/encoder.h source/encoder/frameencoder.cpp source/x265.h
diffstat 9 files changed, 76 insertions(+-), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 @@ changes made to the parameters for auto-
      *     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
--- 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(NATIVE_BUILD "Target the build CP
 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"
--- 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 @@ public:
 
     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
--- 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 @@ namespace X265_NS {
 class ShortYuv;
 struct SPS;
 
-class PicYuv
+class PicYuv : public x265_picyuv
 {
 public:
 
--- 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 @@ int x265_get_slicetype_poc_and_scenecut(
     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 @@ static const x265_api libapi =
     &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);
--- 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 @@ int Encoder::copySlicetypePocAndSceneCut
     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
--- 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 @@ public:
 
     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);
--- 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 @@ void FrameEncoder::threadMain()
         }
         compressFrame();
         m_done.trigger(); /* FrameEncoder::getEncodedPicture() blocks for this event */
+        if (m_frame != NULL)
+            m_frame->m_reconEncoded.trigger();
         m_enable.wait();
     }
 }
--- 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 @@ extern "C" {
  *      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 @@ int x265_encoder_ctu_info(x265_encoder *
  *     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 @@ typedef struct x265_api
     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;