Commit 08eef8bf authored by jehan's avatar jehan

test c based downscaling for IOS

parent e52635ac
......@@ -65,6 +65,71 @@
@implementation IOSMsWebCam
void y_line_down_scale_inplace(uint8_t* r_buff_from_end, uint8_t* w_buff_from_end,unsigned int src_width,unsigned int dest_width,unsigned int pixel_index_to_remove) {
for (int j=dest_width;j>0;j-=pixel_index_to_remove) {
for(int i=pixel_index_to_remove;i>0;i--) {
*(w_buff_from_end--)=*(r_buff_from_end--);
}
r_buff_from_end--;
}
}
void cbcr_line_down_scale_inplace(uint16_t* buff_from_end,uint16_t* w_buff_from_end, unsigned int src_width,unsigned int dest_width,unsigned int pixel_index_to_remove) {
for (int j=dest_width;j>0;j-=pixel_index_to_remove) {
for(int i=pixel_index_to_remove;i>0;i--) {
*(w_buff_from_end--)=*(buff_from_end--);
}
buff_from_end--;
}
}
void y_image_down_scale_inplace(uint8_t* src
,unsigned int src_width
,unsigned int src_height
,unsigned int dest_width
,unsigned int dest_height
) {
unsigned int pixel_index_to_remove=src_width/(src_width - dest_width);
unsigned int line_index_to_remove=src_height / (src_height - dest_height);
uint8_t* r_buff_from_end = src+src_width*src_height;
uint8_t* w_buff_from_end = src+src_width*src_height;
for (int j=dest_height;j>0;j-=line_index_to_remove) {
for(int i=line_index_to_remove;i>0;i--) {
y_line_down_scale_inplace(r_buff_from_end,w_buff_from_end,src_width,dest_width,pixel_index_to_remove);
r_buff_from_end-=src_width;
w_buff_from_end-=src_width;
}
r_buff_from_end-=src_width;
}
}
void crcb_image_down_scale_inplace(uint16_t* src
,unsigned int src_width
,unsigned int src_height
,unsigned int dest_width
,unsigned int dest_height
) {
unsigned int pixel_index_to_remove=src_width/(src_width - dest_width);
unsigned int line_index_to_remove=src_height / (src_height - dest_height);
uint16_t* r_buff_from_end = src+src_width*src_height;
uint16_t* w_buff_from_end = src+src_width*src_height;
for (int j=dest_height;j>0;j-=line_index_to_remove) {
for(int i=line_index_to_remove;i>0;i--) {
cbcr_line_down_scale_inplace(r_buff_from_end,w_buff_from_end,src_width,dest_width,pixel_index_to_remove);
r_buff_from_end-=src_width;
w_buff_from_end-=src_width;
}
r_buff_from_end-=src_width;
}
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
......@@ -81,14 +146,27 @@ didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer
/*kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange*/
size_t plane_width = MIN(CVPixelBufferGetWidthOfPlane(frame, 0),mAbsoluteSize.width);
size_t plane_height = MIN(CVPixelBufferGetHeightOfPlane(frame, 0),mAbsoluteSize.height);
//size_t cbcr_plane_height = CVPixelBufferGetHeightOfPlane(frame, 1);
//size_t cbcr_plane_width = CVPixelBufferGetWidthOfPlane(frame, 1);
size_t plane_width = CVPixelBufferGetWidthOfPlane(frame, 0);
size_t plane_height = CVPixelBufferGetHeightOfPlane(frame, 0);
size_t cbcr_plane_height = CVPixelBufferGetHeightOfPlane(frame, 1);
size_t cbcr_plane_width = CVPixelBufferGetWidthOfPlane(frame, 1);
y_image_down_scale_inplace(CVPixelBufferGetBaseAddressOfPlane(frame, 0)
,plane_width
,plane_height
,mAbsoluteSize.width
,mAbsoluteSize.height
);
crcb_image_down_scale_inplace(CVPixelBufferGetBaseAddressOfPlane(frame,1)
,cbcr_plane_width
,cbcr_plane_height
,mAbsoluteSize.width/2
,mAbsoluteSize.height/2
);
// center image before cropping
int y_offset = 0;//(CVPixelBufferGetWidthOfPlane(frame, 0)- plane_height)/2 + CVPixelBufferGetBytesPerRowOfPlane(frame, 0)*(CVPixelBufferGetHeightOfPlane(frame, 0) - plane_width)/2;
int cbcr_ofset = 0;//(CVPixelBufferGetWidthOfPlane(frame, 1)- plane_height/2) + CVPixelBufferGetBytesPerRowOfPlane(frame, 1)*(CVPixelBufferGetHeightOfPlane(frame, 1) - plane_width/2)/2;
int y_offset = CVPixelBufferGetWidthOfPlane(frame, 0) *(plane_height-mAbsoluteSize.height) + plane_width - mAbsoluteSize.width;
int cbcr_ofset = 2*(CVPixelBufferGetWidthOfPlane(frame, 1) *(cbcr_plane_height-mAbsoluteSize.height/2) + cbcr_plane_width - mAbsoluteSize.width/2);
uint8_t* y_src= CVPixelBufferGetBaseAddressOfPlane(frame, 0) + y_offset;
uint8_t* cbcr_src= CVPixelBufferGetBaseAddressOfPlane(frame, 1) + cbcr_ofset;
int rotation=0;
......@@ -246,8 +324,8 @@ static AVCaptureVideoOrientation devideOrientation2AVCaptureVideoOrientation(int
mCaptureSize.width=MS_VIDEO_SIZE_QVGA_W;
mCaptureSize.height=MS_VIDEO_SIZE_QVGA_H;
}*/
mAbsoluteSize.width=MS_VIDEO_SIZE_IOS_MEDIUM_W;
mAbsoluteSize.height=MS_VIDEO_SIZE_IOS_MEDIUM_H;
mAbsoluteSize.width=MS_VIDEO_SIZE_QVGA_W;
mAbsoluteSize.height=MS_VIDEO_SIZE_QVGA_H;
if (mDeviceOrientation == 0 || mDeviceOrientation == 180) {
mCaptureSize.width=mAbsoluteSize.height;
......
......@@ -466,10 +466,14 @@ static MSScalerContext *ff_create_swscale_context(int src_w, int src_h, MSPixFmt
int ff_flags=0;
MSFFScalerContext *ctx=ms_new(MSFFScalerContext,1);
ctx->src_h=src_h;
#if (TARGET_OS_IPHONE)
ff_flags|=SWS_FAST_BILINEAR;
#else
if (flags & MS_SCALER_METHOD_BILINEAR)
ff_flags|=SWS_BILINEAR;
else if (flags & MS_SCALER_METHOD_NEIGHBOUR)
ff_flags|=SWS_BILINEAR;
#endif
ctx->ctx=sws_getContext (src_w,src_h,ms_pix_fmt_to_ffmpeg (src_fmt),
dst_w,dst_h,ms_pix_fmt_to_ffmpeg (dst_fmt),ff_flags,NULL,NULL,NULL);
if (ctx->ctx==NULL){
......
......@@ -373,19 +373,17 @@ JNIEXPORT jint JNICALL Java_org_linphone_mediastream_MediastreamerActivity_runMe
return res;
}
int _main(int argc, char * argv[])
#else
#endif
#ifndef __APPLE__
int main(int argc, char * argv[])
#else /*Main thread is blocked by cocoa UI framework*/
int g_argc;
char** g_argv;
static int __main(int argc, char * argv[]);
static int _main(int argc, char * argv[]);
static void* apple_main(void* data) {
__main(g_argc,g_argv);
_main(g_argc,g_argv);
return NULL;
}
int main(int argc, char * argv[]) {
......@@ -406,7 +404,7 @@ int main(int argc, char * argv[]) {
pthread_join(main_thread,NULL);
}
static int __main(int argc, char * argv[])
static int _main(int argc, char * argv[])
#endif
{
int i;
......@@ -759,17 +757,17 @@ static void run_media_streams(int localport, const char *remote_ip, int remotepo
}
rtp_stats_display(rtp_session_get_stats(session),"RTP stats");
if (session){
printf("Bandwidth usage: download=%f kbits/sec, upload=%f kbits/sec\n",
ms_message("Bandwidth usage: download=%f kbits/sec, upload=%f kbits/sec\n",
rtp_session_compute_recv_bandwidth(session)*1e-3,
rtp_session_compute_send_bandwidth(session)*1e-3);
parse_events(session,q);
printf("Quality indicator : %f\n",audio ? audio_stream_get_quality_rating(audio) : -1);
ms_message("Quality indicator : %f\n",audio ? audio_stream_get_quality_rating(audio) : -1);
}
}
}
printf("stopping all...\n");
printf("Average quality indicator: %f",audio ? audio_stream_get_average_quality_rating(audio) : -1);
ms_message("stopping all...\n");
ms_message("Average quality indicator: %f",audio ? audio_stream_get_average_quality_rating(audio) : -1);
if (audio) audio_stream_stop(audio);
#ifdef VIDEO_ENABLED
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment