@@ -130,7 +130,10 @@ struct HapCodecCompressTask
130
130
{
131
131
HapCompressorGlobals glob ;
132
132
ICMCompressorSourceFrameRef sourceFrame ;
133
+ CVPixelBufferRef sourceFramePixelBuffer ;
134
+ const uint8_t * sourceFramePixelBufferBaseAddress ;
133
135
ICMMutableEncodedFrameRef encodedFrame ;
136
+ UInt8 * encodedFrameDataPtr ;
134
137
unsigned long encodedFrameActualSize ;
135
138
HapCodecBufferRef dxtBuffer ;
136
139
ComponentResult error ;
@@ -636,7 +639,7 @@ static void Encode_Slice(void *p, unsigned int index)
636
639
HapCodecEncodeDXTTask * task = (HapCodecEncodeDXTTask * )p ;
637
640
638
641
unsigned int sliceHeight = task -> sliceHeight ;
639
- if ((index + 1 ) * sliceHeight > task -> height )
642
+ if ((index + 1 ) * sliceHeight > ( unsigned int ) task -> height )
640
643
sliceHeight = task -> height - (index * sliceHeight );
641
644
642
645
const uint8_t * src = task -> source + (index * task -> sliceHeight * task -> sourceBytesPerRow );
@@ -704,7 +707,6 @@ static void Background_Encode(void *info)
704
707
{
705
708
HapCodecCompressTask * task = (HapCodecCompressTask * )HapCodecBufferGetBaseAddress ((HapCodecBufferRef )info );
706
709
HapCompressorGlobals glob = task -> glob ;
707
- CVPixelBufferRef pixelBuffer = ICMCompressorSourceFrameGetPixelBuffer (task -> sourceFrame );
708
710
709
711
const void * codec_src = NULL ;
710
712
unsigned int codec_src_length = 0 ;
@@ -720,21 +722,15 @@ static void Background_Encode(void *info)
720
722
}
721
723
else
722
724
{
723
- if (CVPixelBufferLockBaseAddress (pixelBuffer , kHapCodecCVPixelBufferLockFlags ) != kCVReturnSuccess )
724
- {
725
- err = internalComponentErr ;
726
- goto bail ;
727
- }
728
-
729
- codec_src = CVPixelBufferGetBaseAddress (pixelBuffer );
725
+ codec_src = task -> sourceFramePixelBufferBaseAddress ;
730
726
codec_src_length = dxtBytesForDimensions (glob -> width , glob -> height , glob -> type );
731
727
}
732
728
733
729
hapResult = HapEncode (codec_src ,
734
730
codec_src_length ,
735
731
glob -> dxtFormat ,
736
732
HapCompressorSnappy ,
737
- ICMEncodedFrameGetDataPtr ( task -> encodedFrame ) ,
733
+ task -> encodedFrameDataPtr ,
738
734
glob -> maxEncodedDataSize ,
739
735
& (task -> encodedFrameActualSize ));
740
736
@@ -761,15 +757,15 @@ static void Background_Encode(void *info)
761
757
HapCodecBufferReturn (task -> dxtBuffer );
762
758
task -> dxtBuffer = NULL ;
763
759
}
764
-
765
- if (pixelBuffer )
766
- {
767
- CVPixelBufferUnlockBaseAddress (pixelBuffer , kHapCodecCVPixelBufferLockFlags );
768
760
#if defined(__APPLE__ )
761
+ if (task -> sourceFramePixelBuffer )
762
+ {
763
+ CVPixelBufferUnlockBaseAddress (task -> sourceFramePixelBuffer , kHapCodecCVPixelBufferLockFlags );
769
764
// Detach the pixel buffer so it can be recycled (not on Windows as QT isn't thread-safe there)
770
765
ICMCompressorSourceFrameDetachPixelBuffer (task -> sourceFrame );
771
- #endif
766
+ task -> sourceFramePixelBuffer = NULL ;
772
767
}
768
+ #endif
773
769
774
770
task -> error = err ;
775
771
@@ -1050,6 +1046,10 @@ static void disposeTask(HapCodecCompressTask *task)
1050
1046
{
1051
1047
if (task )
1052
1048
{
1049
+ if (task -> sourceFramePixelBuffer )
1050
+ {
1051
+ CVPixelBufferUnlockBaseAddress (task -> sourceFramePixelBuffer , kHapCodecCVPixelBufferLockFlags );
1052
+ }
1053
1053
ICMCompressorSourceFrameRelease (task -> sourceFrame );
1054
1054
ICMEncodedFrameRelease (task -> encodedFrame );
1055
1055
HapCodecBufferReturn (task -> dxtBuffer );
@@ -1148,8 +1148,19 @@ static HapCodecBufferRef createTask(HapCompressorGlobals glob, HapCodecBufferRef
1148
1148
HapCodecCompressTask * task = (HapCodecCompressTask * )HapCodecBufferGetBaseAddress (buffer );
1149
1149
1150
1150
task -> sourceFrame = ICMCompressorSourceFrameRetain (sourceFrame );
1151
+ task -> sourceFramePixelBuffer = ICMCompressorSourceFrameGetPixelBuffer (sourceFrame );
1152
+ if (task -> sourceFramePixelBuffer )
1153
+ {
1154
+ CVPixelBufferLockBaseAddress (task -> sourceFramePixelBuffer , kHapCodecCVPixelBufferLockFlags );
1155
+ task -> sourceFramePixelBufferBaseAddress = CVPixelBufferGetBaseAddress (task -> sourceFramePixelBuffer );
1156
+ }
1157
+ else
1158
+ {
1159
+ task -> sourceFramePixelBufferBaseAddress = NULL ;
1160
+ }
1151
1161
task -> glob = glob ;
1152
1162
task -> encodedFrame = (ICMMutableEncodedFrameRef )ICMEncodedFrameRetain (encodedFrame );
1163
+ task -> encodedFrameDataPtr = ICMEncodedFrameGetDataPtr (encodedFrame );
1153
1164
task -> error = noErr ;
1154
1165
task -> next = NULL ;
1155
1166
task -> dxtBuffer = dxtBuffer ;
0 commit comments