~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/codec/xvid/video_xvid.cc

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * The contents of this file are subject to the Mozilla Public
  3  * License Version 1.1 (the "License"); you may not use this file
  4  * except in compliance with the License. You may obtain a copy of
  5  * the License at http://www.mozilla.org/MPL/
  6  * 
  7  * Software distributed under the License is distributed on an "AS
  8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9  * implied. See the License for the specific language governing
 10  * rights and limitations under the License.
 11  * 
 12  * The Original Code is MPEG4IP.
 13  * 
 14  * The Initial Developer of the Original Code is Cisco Systems Inc.
 15  * Portions created by Cisco Systems Inc. are
 16  * Copyright (C) Cisco Systems Inc. 2000, 2001.  All Rights Reserved.
 17  * 
 18  * Contributor(s): 
 19  *              Dave Mackie             dmackie@cisco.com
 20  */
 21 
 22 #include "video_xvid.h"
 23 #include "util.h"
 24 
 25 CXvidVideoEncoder::CXvidVideoEncoder()
 26 {
 27         m_xvidHandle = NULL;
 28         m_vopBuffer = NULL;
 29         m_vopBufferLength = 0;
 30         CONFIG_VIDEO_TIMEBITS = 0;
 31         CONFIG_VIDEO_BIT_RATE = 500;
 32         CONFIG_VIDEO_FRAME_RATE = 29.97;
 33         CONFIG_VIDEO_KEY_FRAME_INTERVAL = 2.0;
 34 
 35 }
 36 
 37 bool CXvidVideoEncoder::Init(int height_, int width_, bool realTime)
 38 {
 39 
 40         XVID_INIT_PARAM xvidInitParams;
 41 
 42         memset(&xvidInitParams, 0, sizeof(xvidInitParams));
 43 
 44         if (xvid_init(NULL, 0, &xvidInitParams, NULL) != XVID_ERR_OK) {
 45                 //error_message("Failed to initialize Xvid");
 46                 return false;
 47         }
 48 
 49         XVID_ENC_PARAM xvidEncParams;
 50 
 51         memset(&xvidEncParams, 0, sizeof(xvidEncParams));
 52 
 53         xvidEncParams.width = width_;
 54         xvidEncParams.height = height_;
 55         if (CONFIG_VIDEO_TIMEBITS == 0) {
 56           xvidEncParams.fincr = 1;
 57           xvidEncParams.fbase = 
 58             (int)(CONFIG_VIDEO_FRAME_RATE + 0.5);
 59           xvidEncParams.dont_simplify_fincr = 0;
 60         } else {
 61           xvidEncParams.fincr = 
 62             (int)(((double)CONFIG_VIDEO_TIMEBITS) /
 63                   CONFIG_VIDEO_FRAME_RATE);
 64           xvidEncParams.fbase = 
 65             CONFIG_VIDEO_TIMEBITS;
 66           xvidEncParams.dont_simplify_fincr = 1;
 67         }
 68 
 69         // xvidEncParams.bitrate = CONFIG_VIDEO_BIT_RATE * 1000;
 70         xvidEncParams.rc_buffersize = 16;
 71         xvidEncParams.min_quantizer = 1;
 72         xvidEncParams.max_quantizer = 31;
 73         xvidEncParams.max_key_interval = (int)
 74                 (CONFIG_VIDEO_FRAME_RATE 
 75                  * CONFIG_VIDEO_KEY_FRAME_INTERVAL);
 76         if (xvidEncParams.max_key_interval == 0) {
 77                 xvidEncParams.max_key_interval = 1;
 78         } 
 79 
 80         if (xvid_encore(NULL, XVID_ENC_CREATE, &xvidEncParams, NULL) 
 81           != XVID_ERR_OK) {
 82                 //error_message("Failed to initialize Xvid encoder");
 83                 return false;
 84         }
 85 
 86         m_xvidHandle = xvidEncParams.handle; 
 87 
 88         memset(&m_xvidFrame, 0, sizeof(m_xvidFrame));
 89 
 90         m_xvidFrame.general = XVID_HALFPEL | XVID_H263QUANT;
 91         if (!realTime) {
 92                 m_xvidFrame.motion = 
 93                         PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 
 94                         | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8;
 95         } else {
 96                 m_xvidFrame.motion = PMV_QUICKSTOP16;
 97         }
 98                 if (!realTime) {
 99                         m_xvidFrame.general |= XVID_INTER4V;
100                 }
101         m_xvidFrame.colorspace = XVID_CSP_I420;
102         m_xvidFrame.quant = 0;
103 
104         return true;
105 }
106 
107 bool CXvidVideoEncoder::EncodeImage(
108         u_int8_t* pY, 
109         u_int8_t* pU, 
110         u_int8_t* pV, 
111         u_int32_t yStride,
112         u_int32_t uvStride,
113         bool wantKeyFrame,
114         u_int32_t videoMaxVopSize)
115 {
116         m_vopBuffer = (u_int8_t*)malloc(videoMaxVopSize);
117         if (m_vopBuffer == NULL) {
118                 return false;
119         }
120 
121         m_xvidFrame.image_y = pY;
122         m_xvidFrame.image_u = pU;
123         m_xvidFrame.image_v = pV;
124         m_xvidFrame.stride = yStride;
125         m_xvidFrame.bitstream = m_vopBuffer;
126         m_xvidFrame.intra = (wantKeyFrame ? 1 : -1);
127 
128         if (xvid_encore(m_xvidHandle, XVID_ENC_ENCODE, &m_xvidFrame, 
129           &m_xvidResult) != XVID_ERR_OK) {
130                 //debug_message("Xvid can't encode frame!");
131                 return false;
132         }
133 
134         m_vopBufferLength = m_xvidFrame.length;
135 
136         return true;
137 }
138 
139 bool CXvidVideoEncoder::GetEncodedImage(
140         u_int8_t** ppBuffer, u_int32_t* pBufferLength)
141 {
142         *ppBuffer = m_vopBuffer;
143         *pBufferLength = m_vopBufferLength;
144 
145         m_vopBuffer = NULL;
146         m_vopBufferLength = 0;
147 
148         return true;
149 }
150 
151 bool CXvidVideoEncoder::GetReconstructedImage(
152         u_int8_t* pY, u_int8_t* pU, u_int8_t* pV, int height_, int width_)
153 {
154         
155         imgcpy(pY, (u_int8_t*)m_xvidResult.image_y,
156                 width_, 
157                 height_,
158                 m_xvidResult.stride_y);
159 
160         imgcpy(pU, (u_int8_t*)m_xvidResult.image_u,
161                 width_ / 2, 
162                 height_ / 2,
163                 m_xvidResult.stride_uv);
164 
165         imgcpy(pV, (u_int8_t*)m_xvidResult.image_v,
166                 width_ / 2, 
167                 height_ / 2,
168                 m_xvidResult.stride_uv);
169 
170         return true;
171 }
172 
173 void CXvidVideoEncoder::Stop()
174 {
175         xvid_encore(m_xvidHandle, XVID_ENC_DESTROY, NULL, NULL);
176         m_xvidHandle = NULL;
177 }
178 
179 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.