All pastes #3411148 Raw Edit

Miscellany

public unlisted text v1 · immutable
#3411148 ·published 2016-03-25 15:54 UTC
rendered paste body
diff --git a/FFMpegDecoder/RTSPPlayer.m b/FFMpegDecoder/RTSPPlayer.m
index 0229c80..2e5689a 100755
--- a/FFMpegDecoder/RTSPPlayer.m
+++ b/FFMpegDecoder/RTSPPlayer.m
@@ -44,7 +44,7 @@ BOOL bFirstFrame = YES;
 {
     if (!pFrame->data[0]) return nil;
     [self convertFrameToRGB];
-    return [self imageFromAVPicture:picture width:outputWidth height:outputHeight];
+    return [self imageFromAV: outputWidth height:outputHeight];
 }
 
 - (double)duration
@@ -191,11 +191,19 @@ initError:
     
     if(outputHeight > 0 && outputWidth > 0){
         // Release old picture and scaler
-        avpicture_free(&picture);
+        //avpicture_free(&picture);
+        av_freep(&dst_data[0]);
         sws_freeContext(img_convert_ctx);
         
         // Allocate RGB picture
-        avpicture_alloc(&picture, AV_PIX_FMT_RGB24, outputWidth, outputHeight);
+        //avpicture_alloc(&picture, AV_PIX_FMT_RGB24, outputWidth, outputHeight);
+        int ret;
+        if ((ret= av_image_alloc(dst_data,dst_linesize,outputWidth, outputHeight,AV_PIX_FMT_RGB24,1)) < 0){
+            ALog("Failed to allocate buffer for scalar");
+            
+            //TODO HOW DO U HANDLE ERROR HERE.
+        }
+        dst_bufsize=ret;
         
         // Setup scaler
         static int sws_flags =  SWS_FAST_BILINEAR;
@@ -224,7 +232,8 @@ initError:
     sws_freeContext(img_convert_ctx);
     
     // Free RGB picture
-    avpicture_free(&picture);
+    //avpicture_free(&picture);
+    av_freep(&dst_data[0]);
     
     // Free the packet that was allocated by av_read_frame
     av_packet_unref(&packet);
@@ -283,24 +292,24 @@ initError:
                   pFrame->linesize,
                   0,
                   pCodecCtx->height,
-                  picture.data,
-                  picture.linesize);
+                  dst_data,
+                  dst_linesize);
     } else {
         av_log(NULL, AV_LOG_ERROR, "Image context is nil\n");
     }
 }

-- (UIImage *)imageFromAVPicture:(AVPicture)pict width:(int)width height:(int)height
+- (UIImage *)imageFromAV:(int)width height:(int)height
 {
     CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
-    CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, pict.data[0], pict.linesize[0]*height,kCFAllocatorNull);
+    CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, dst_data[0], dst_linesize[0]*height,kCFAllocatorNull);
     CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGImageRef cgImage = CGImageCreate(width,
                                        height,
                                        8, 
                                        24, 
-                                       pict.linesize[0], 
+                                       dst_linesize[0],
                                        colorSpace, 
                                        bitmapInfo, 
                                        provider,