Commit e13dd416 authored by Simon Morlat's avatar Simon Morlat
Browse files

display override

parent 9d112433
......@@ -229,7 +229,7 @@ int video_stream_send_only_start(VideoStream *videostream,
void video_stream_recv_only_stop(VideoStream *vs);
void video_stream_send_only_stop(VideoStream *vs);
VideoStream * video_preview_start(MSWebCam *device, MSVideoSize vsize);
VideoStream * video_preview_start(MSWebCam *device, MSVideoSize disp_size, const char *displaytype);
void video_preview_stop(VideoStream *stream);
bool_t ms_is_ipv6(const char *address);
......
......@@ -59,46 +59,77 @@ static int take_snapshot(MSFilter *f, void *arg){
return 0;
}
static void cleanup(JpegWriter *s, AVCodecContext *avctx){
if (s->file){
fclose(s->file);
s->file=NULL;
}
if (avctx){
avcodec_close(avctx);
av_free(avctx);
}
}
static void jpg_process(MSFilter *f){
JpegWriter *s=(JpegWriter*)f->data;
if (s->file!=NULL && s->codec!=NULL){
MSPicture yuvbuf;
mblk_t *m=ms_queue_get(f->inputs[0]);
MSPicture yuvbuf, yuvjpeg;
mblk_t *m=ms_queue_peek_last(f->inputs[0]);
if (yuv_buf_init_from_mblk(&yuvbuf,m)==0){
int error;
int comp_buf_sz=msgdsize(m);
uint8_t *comp_buf=(uint8_t*)alloca(comp_buf_sz);
AVFrame pict;
mblk_t *jpegm;
struct ms_SwsContext *sws_ctx;
AVCodecContext *avctx=avcodec_alloc_context();
avctx->width=yuvbuf.w;
avctx->height=yuvbuf.h;
avctx->pix_fmt=PIX_FMT_YUV420P;
avctx->time_base.num = 1;
avctx->time_base.den =1;
avctx->pix_fmt=PIX_FMT_YUVJ420P;
error=avcodec_open(avctx,s->codec);
if (error!=0) {
ms_error("avcodec_open() failed: %i",error);
cleanup(s,NULL);
av_free(avctx);
return;
}
sws_ctx=ms_sws_getContext(avctx->width,avctx->height,PIX_FMT_YUV420P,
avctx->width,avctx->height,avctx->pix_fmt,SWS_FAST_BILINEAR,NULL, NULL, NULL);
if (sws_ctx==NULL) {
ms_error(" ms_sws_getContext() failed.");
cleanup(s,avctx);
goto end;
}
jpegm=yuv_buf_alloc (&yuvjpeg,avctx->width, avctx->height);
if (ms_sws_scale(sws_ctx,yuvbuf.planes,yuvbuf.strides,0,avctx->height,yuvjpeg.planes,yuvjpeg.strides)<0){
ms_error("ms_sws_scale() failed.");
ms_sws_freeContext(sws_ctx);
cleanup(s,avctx);
freemsg(jpegm);
goto end;
}
ms_sws_freeContext(sws_ctx);
avcodec_get_frame_defaults(&pict);
avpicture_fill((AVPicture*)&pict,(uint8_t*)m->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
avpicture_fill((AVPicture*)&pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
error=avcodec_encode_video(avctx, (uint8_t*)comp_buf,comp_buf_sz, &pict);
if (error<0){
ms_error("Could not encode jpeg picture.");
}else{
fwrite(comp_buf,error,1,s->file);
ms_message("Snapshot done");
}
fclose(s->file);
s->file=NULL;
avcodec_close(avctx);
av_free(avctx);
cleanup(s,avctx);
freemsg(jpegm);
}
freemsg(m);
goto end;
}
end:
ms_queue_flush(f->inputs[0]);
}
......
......@@ -483,7 +483,7 @@ unsigned long video_stream_get_native_window_id(VideoStream *stream){
}
VideoStream * video_preview_start(MSWebCam *device, MSVideoSize disp_size){
VideoStream * video_preview_start(MSWebCam *device, MSVideoSize disp_size, const char *displaytype){
VideoStream *stream = (VideoStream *)ms_new0 (VideoStream, 1);
MSVideoSize vsize=disp_size;
MSPixFmt format;
......@@ -492,7 +492,10 @@ VideoStream * video_preview_start(MSWebCam *device, MSVideoSize disp_size){
int corner=-1;
/* creates the filters */
choose_display_name(stream);
if(!displaytype)
choose_display_name(stream);
else
video_stream_set_display_filter_name(stream,displaytype);
stream->source = ms_web_cam_create_reader(device);
stream->output=ms_filter_new_from_name (stream->display_name);
......
......@@ -47,7 +47,7 @@ int main(int argc, char *argv[]){
/* this is to test the sequence start/stop */
for(i=0;i<1;++i){
int n;
vs=video_preview_start(cam,vsize);
vs=video_preview_start(cam,vsize,NULL);
for(n=0;n<60000 && !stopped;++n){
#ifdef WIN32
......
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