changeset 11896:de91aae2db53 draft

api: 'x265_get_slicetype_poc_and_scenecut' to fetch slicetype, poc and scenecut information
author Praveen Tiwari <praveen@multicorewareinc.com>
date Tue, 31 Oct 2017 13:57:37 +0530
parents 6a310b24c6a2
children 6ad93877ffe1
files doc/reST/api.rst source/CMakeLists.txt source/common/piclist.cpp source/common/piclist.h source/encoder/api.cpp source/encoder/encoder.cpp source/encoder/encoder.h source/x265.h
diffstat 8 files changed, 60 insertions(+-), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/reST/api.rst	Thu Nov 02 12:17:29 2017 +0530
+++ b/doc/reST/api.rst	Tue Oct 31 13:57:37 2017 +0530
@@ -192,6 +192,15 @@ changes made to the parameters for auto-
 	 *      presets is not recommended without a more fine-grained breakdown of
 	 *      parameters to take this into account. */
 	int x265_encoder_reconfig(x265_encoder *, x265_param *);
+
+**x265_get_slicetype_poc_and_scenecut()** may be used to fetch slice type, poc and scene cut information mid-encode::
+
+    /* x265_get_slicetype_poc_and_scenecut:
+     *     get the slice type, poc and scene cut information for the current frame,
+     *     returns negative on error, 0 on success.
+     *     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_encoder_ctu_info**
        /* x265_encoder_ctu_info:
         *    Copy CTU information such as ctu address and ctu partition structure of all
--- a/source/CMakeLists.txt	Thu Nov 02 12:17:29 2017 +0530
+++ b/source/CMakeLists.txt	Tue Oct 31 13:57:37 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 136)
+set(X265_BUILD 137)
 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/piclist.cpp	Thu Nov 02 12:17:29 2017 +0530
+++ b/source/common/piclist.cpp	Tue Oct 31 13:57:37 2017 +0530
@@ -117,6 +117,15 @@ Frame *PicList::popBack()
         return NULL;
 }
 
+Frame* PicList::getCurFrame(void)
+{
+    Frame *curFrame = m_start;
+    if (curFrame != NULL)
+        return curFrame;
+    else
+        return NULL;
+}
+
 void PicList::remove(Frame& curFrame)
 {
 #if _DEBUG
--- a/source/common/piclist.h	Thu Nov 02 12:17:29 2017 +0530
+++ b/source/common/piclist.h	Tue Oct 31 13:57:37 2017 +0530
@@ -62,6 +62,9 @@ public:
     /** Find frame with specified POC */
     Frame* getPOC(int poc);
 
+    /** Get the current Frame from the list **/
+    Frame* getCurFrame(void);
+
     /** Remove picture from list */
     void remove(Frame& pic);
 
--- a/source/encoder/api.cpp	Thu Nov 02 12:17:29 2017 +0530
+++ b/source/encoder/api.cpp	Tue Oct 31 13:57:37 2017 +0530
@@ -340,6 +340,16 @@ int x265_encoder_ctu_info(x265_encoder *
     return 0;
 }
 
+int x265_get_slicetype_poc_and_scenecut(x265_encoder *enc, int *slicetype, int *poc, int *sceneCut)
+{
+    if (!enc)
+        return -1;
+    Encoder *encoder = static_cast<Encoder*>(enc);
+    if (!encoder->copySlicetypePocAndSceneCut(slicetype, poc, sceneCut))
+        return 0;
+    return -1;
+}
+
 void x265_cleanup(void)
 {
     BitCost::destroy();
@@ -413,6 +423,7 @@ static const x265_api libapi =
     sizeof(x265_frame_stats),
     &x265_encoder_intra_refresh,
     &x265_encoder_ctu_info,
+    &x265_get_slicetype_poc_and_scenecut,
 };
 
 typedef const x265_api* (*api_get_func)(int bitDepth);
--- a/source/encoder/encoder.cpp	Thu Nov 02 12:17:29 2017 +0530
+++ b/source/encoder/encoder.cpp	Tue Oct 31 13:57:37 2017 +0530
@@ -429,6 +429,23 @@ void Encoder::stopJobs()
     }
 }
 
+int Encoder::copySlicetypePocAndSceneCut(int *slicetype, int *poc, int *sceneCut)
+{
+    Frame *FramePtr = m_dpb->m_picList.getCurFrame();
+    if (FramePtr != NULL)
+    {
+        *slicetype = FramePtr->m_lowres.sliceType;
+        *poc = FramePtr->m_encData->m_slice->m_poc;
+        *sceneCut = FramePtr->m_lowres.bScenecut;
+    }
+    else
+    {
+        x265_log(NULL, X265_LOG_WARNING, "Frame is still in lookahead pipeline, this API must be called after (poc >= lookaheadDepth + bframes + 2) condition check\n");
+        return -1;
+    }
+    return 0;
+}
+
 void Encoder::destroy()
 {
 #if ENABLE_HDR10_PLUS
--- a/source/encoder/encoder.h	Thu Nov 02 12:17:29 2017 +0530
+++ b/source/encoder/encoder.h	Tue Oct 31 13:57:37 2017 +0530
@@ -205,6 +205,8 @@ public:
 
     void copyCtuInfo(x265_ctu_info_t** frameCtuInfo, int poc);
 
+    int copySlicetypePocAndSceneCut(int *slicetype, int *poc, int *sceneCut);
+
     void getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs);
 
     void fetchStats(x265_stats* stats, size_t statsSizeBytes);
--- a/source/x265.h	Thu Nov 02 12:17:29 2017 +0530
+++ b/source/x265.h	Tue Oct 31 13:57:37 2017 +0530
@@ -1705,6 +1705,13 @@ int x265_encoder_intra_refresh(x265_enco
 int x265_encoder_ctu_info(x265_encoder *, int poc, x265_ctu_info_t** ctu);
 /* x265_cleanup:
  *       release library static allocations, reset configured CTU size */
+
+/* x265_get_slicetype_poc_and_scenecut:
+ *     get the slice type, poc and scene cut information for the current frame,
+ *     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_slicetype_poc_and_scenecut(x265_encoder *encoder, int *slicetype, int *poc, int* sceneCut);
+
 void x265_cleanup(void);
 
 #define X265_MAJOR_VERSION 1
@@ -1752,6 +1759,7 @@ typedef struct x265_api
     int           sizeof_frame_stats;   /* sizeof(x265_frame_stats) */
     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*);
     /* add new pointers to the end, or increment X265_MAJOR_VERSION */
 } x265_api;