Libav 0.7.1
|
00001 /* 00002 * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com > 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00026 #include "libdirac_libschro.h" 00027 #include "libschroedinger.h" 00028 00033 static const SchroVideoFormatEnum ff_schro_video_formats[]={ 00034 SCHRO_VIDEO_FORMAT_CUSTOM , 00035 SCHRO_VIDEO_FORMAT_QSIF , 00036 SCHRO_VIDEO_FORMAT_QCIF , 00037 SCHRO_VIDEO_FORMAT_SIF , 00038 SCHRO_VIDEO_FORMAT_CIF , 00039 SCHRO_VIDEO_FORMAT_4SIF , 00040 SCHRO_VIDEO_FORMAT_4CIF , 00041 SCHRO_VIDEO_FORMAT_SD480I_60 , 00042 SCHRO_VIDEO_FORMAT_SD576I_50 , 00043 SCHRO_VIDEO_FORMAT_HD720P_60 , 00044 SCHRO_VIDEO_FORMAT_HD720P_50 , 00045 SCHRO_VIDEO_FORMAT_HD1080I_60 , 00046 SCHRO_VIDEO_FORMAT_HD1080I_50 , 00047 SCHRO_VIDEO_FORMAT_HD1080P_60 , 00048 SCHRO_VIDEO_FORMAT_HD1080P_50 , 00049 SCHRO_VIDEO_FORMAT_DC2K_24 , 00050 SCHRO_VIDEO_FORMAT_DC4K_24 , 00051 }; 00052 00053 SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avccontext) 00054 { 00055 unsigned int num_formats = sizeof(ff_schro_video_formats) / 00056 sizeof(ff_schro_video_formats[0]); 00057 00058 unsigned int idx = ff_dirac_schro_get_video_format_idx (avccontext); 00059 00060 return (idx < num_formats) ? ff_schro_video_formats[idx] : 00061 SCHRO_VIDEO_FORMAT_CUSTOM; 00062 } 00063 00064 int ff_get_schro_frame_format (SchroChromaFormat schro_pix_fmt, 00065 SchroFrameFormat *schro_frame_fmt) 00066 { 00067 unsigned int num_formats = sizeof(ffmpeg_schro_pixel_format_map) / 00068 sizeof(ffmpeg_schro_pixel_format_map[0]); 00069 00070 int idx; 00071 00072 for (idx = 0; idx < num_formats; ++idx) { 00073 if (ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) { 00074 *schro_frame_fmt = ffmpeg_schro_pixel_format_map[idx].schro_frame_fmt; 00075 return 0; 00076 } 00077 } 00078 return -1; 00079 } 00080 00081 static void FreeSchroFrame(SchroFrame *frame, void *priv) 00082 { 00083 AVPicture *p_pic = priv; 00084 00085 if (!p_pic) 00086 return; 00087 00088 avpicture_free(p_pic); 00089 av_freep(&p_pic); 00090 } 00091 00092 SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext, 00093 SchroFrameFormat schro_frame_fmt) 00094 { 00095 AVPicture *p_pic; 00096 SchroFrame *p_frame; 00097 int y_width, uv_width; 00098 int y_height, uv_height; 00099 int i; 00100 00101 y_width = avccontext->width; 00102 y_height = avccontext->height; 00103 uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt)); 00104 uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt)); 00105 00106 p_pic = av_mallocz(sizeof(AVPicture)); 00107 avpicture_alloc(p_pic, avccontext->pix_fmt, y_width, y_height); 00108 00109 p_frame = schro_frame_new(); 00110 p_frame->format = schro_frame_fmt; 00111 p_frame->width = y_width; 00112 p_frame->height = y_height; 00113 schro_frame_set_free_callback(p_frame, FreeSchroFrame, (void *)p_pic); 00114 00115 for (i = 0; i < 3; ++i) { 00116 p_frame->components[i].width = i ? uv_width : y_width; 00117 p_frame->components[i].stride = p_pic->linesize[i]; 00118 p_frame->components[i].height = i ? uv_height : y_height; 00119 p_frame->components[i].length = 00120 p_frame->components[i].stride * p_frame->components[i].height; 00121 p_frame->components[i].data = p_pic->data[i]; 00122 00123 if (i) { 00124 p_frame->components[i].v_shift = 00125 SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format); 00126 p_frame->components[i].h_shift = 00127 SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format); 00128 } 00129 } 00130 00131 return p_frame; 00132 }