@@ -191,10 +191,6 @@ bool cmpc::CMpegClient::FFmpegSetup() {
191191 PFormatCtx = avformat_alloc_context ();
192192 PCodecCtx = nullptr ;
193193
194- // Register everything
195- av_register_all ();
196- avformat_network_init ();
197-
198194 /* open RTSP: register all formats and codecs */
199195 if (avformat_open_input (&PFormatCtx, videoPath.c_str (), nullptr , nullptr ) < 0 ) {
200196 cerr << " Could not open source address " << videoPath << endl;
@@ -764,10 +760,20 @@ void cmpc::Buffer_List::freezeWrite(int64_t read_size) {
764760 __Read_size = read_size;
765761}
766762bool cmpc::Buffer_List::write (SwsContext *PswsCtx, AVFrame *frame) {
767- if (frame->pts < next_pts)
768- return false ;
769- else
770- next_pts += interval_pts;
763+ if (frame->pts < next_pts) {
764+ if (frame->pts > (next_pts - 2 * interval_pts)) {
765+ return false ;
766+ }
767+ else {
768+ next_pts = frame->pts + interval_pts;
769+ }
770+ }
771+ else {
772+ if (next_pts > 0 )
773+ next_pts += interval_pts;
774+ else
775+ next_pts = frame->pts ;
776+ }
771777 if (_Buffer_pos == _Buffer_rpos) {
772778 return false ;
773779 }
@@ -782,7 +788,7 @@ PyObject * cmpc::Buffer_List::read() {
782788 if (_Buffer_rpos < 0 ) {
783789 return nullptr ;
784790 }
785- else if (PyArray_API == nullptr ) {
791+ else if (PyArray_API == NULL ) {
786792 import_array ();
787793 }
788794 auto _Buffer_rend = (_Buffer_rpos + __Read_size) % _Buffer_size;
@@ -791,10 +797,12 @@ PyObject * cmpc::Buffer_List::read() {
791797 auto p = newdata;
792798 for (auto i = _Buffer_rpos; i != _Buffer_rend; i = (i + 1 ) % _Buffer_size) {
793799 memcpy (p, _Buffer_List[i], _Buffer_capacity * sizeof (uint8_t ));
794- p += _Buffer_capacity;
800+ p += _Buffer_capacity;
795801 }
796802 PyObject *PyFrame = PyArray_SimpleNewFromData (4 , dims, NPY_UINT8, reinterpret_cast <void *>(newdata));
803+ PyArray_ENABLEFLAGS ((PyArrayObject*)PyFrame, NPY_ARRAY_OWNDATA);
797804 _Buffer_rpos = -1 ;
798805 __Read_size = 0 ;
799- return PyFrame;
806+ return PyArray_Return ((PyArrayObject*)PyFrame);
807+ // Py_RETURN_NONE;
800808}
0 commit comments