@@ -616,8 +616,91 @@ bool CBitstreamConverter::Convert(uint8_t *pData, int iSize)
616
616
}
617
617
else
618
618
{
619
- m_inputSize = iSize;
620
- m_inputBuffer = pData;
619
+ if (m_convert_dovi != DOVIMode::MODE_NONE)
620
+ {
621
+ uint32_t nal_buf_size = iSize;
622
+ AVIOContext *pb;
623
+ uint32_t offset = 0 , size_eos;
624
+ uint8_t *buf=NULL , *end, *start, *buf_eos=NULL ;
625
+
626
+ if (avio_open_dyn_buf (&pb) < 0 )
627
+ return false ;
628
+
629
+ nal_buf_size = avc_parse_nal_units (pb, pData, iSize);
630
+ avio_close_dyn_buf (pb, &buf);
631
+
632
+ // process frame data
633
+ start = buf;
634
+ end = buf + nal_buf_size;
635
+ while (end - buf > 4 )
636
+ {
637
+ uint32_t size;
638
+ uint8_t nal_type;
639
+ size = std::min<uint32_t >(AV_RB32 (buf), end - buf - 4 );
640
+ buf += 4 ;
641
+ nal_type = (buf[0 ] >> 1 ) & 0x3f ;
642
+
643
+ if (nal_type == AVC_NAL_END_SEQUENCE)
644
+ {
645
+ buf_eos = buf;
646
+ size_eos = size;
647
+ }
648
+ else if (nal_type == HEVC_NAL_UNSPEC62)
649
+ {
650
+ const uint8_t *nalu_62_data = buf;
651
+ #ifdef HAVE_LIBDOVI
652
+ const DoviData* rpu_data = NULL ;
653
+ #endif
654
+ if (m_convert_dovi != DOVIMode::MODE_NONE)
655
+ {
656
+ #ifdef HAVE_LIBDOVI
657
+ // Convert the RPU itself
658
+ rpu_data = convert_dovi_rpu_nal (buf, size, m_convert_dovi);
659
+ if (rpu_data)
660
+ {
661
+ nalu_62_data = rpu_data->data ;
662
+ size = rpu_data->len ;
663
+ }
664
+ #endif
665
+ }
666
+
667
+ BitstreamAllocAndCopy (&m_convertBuffer, &offset, nalu_62_data, size, nal_type);
668
+
669
+ #ifdef HAVE_LIBDOVI
670
+ if (rpu_data)
671
+ dovi_data_free (rpu_data);
672
+
673
+ m_dovi_el_type = get_dovi_el_type ((uint8_t *)nalu_62_data, size);
674
+ #endif
675
+ }
676
+ else
677
+ {
678
+ if (m_convert_dovi == DOVIMode::MODE_NONE || nal_type != HEVC_NAL_UNSPEC63)
679
+ BitstreamAllocAndCopy (&m_convertBuffer, &offset, buf, size, nal_type);
680
+ }
681
+
682
+ if (m_convert_dovi == DOVIMode::MODE_NONE || nal_type != HEVC_NAL_UNSPEC63)
683
+ CLog::Log (LOGDEBUG, LOGVIDEO, " CBitstreamConverter::Convert: nal_type: {}, size: {}" ,
684
+ nal_type, size);
685
+
686
+ buf += size;
687
+ }
688
+
689
+ // append end of sequence if exist
690
+ if (buf_eos)
691
+ BitstreamAllocAndCopy (&m_convertBuffer, &offset, buf_eos, size_eos, AVC_NAL_END_SEQUENCE);
692
+
693
+ av_free (start);
694
+
695
+ m_convertSize = offset;
696
+ m_combine = true ;
697
+ }
698
+ else
699
+ {
700
+ m_inputSize = iSize;
701
+ m_inputBuffer = pData;
702
+ }
703
+
621
704
return true ;
622
705
}
623
706
}
0 commit comments