- Timestamp:
- 03/04/09 15:49:39 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
r9857 r9860 2 2 3 3 #include <osg/Notify> 4 #include <osg/Timer> 4 5 5 6 #include <stdexcept> … … 17 18 m_bytes_remaining(0), 18 19 m_packet_pts(AV_NOPTS_VALUE), 20 m_writeBuffer(0), 19 21 m_user_data(0), 20 22 m_publish_func(0), … … 84 86 // Allocate converted RGB frame 85 87 m_frame_rgba.reset(avcodec_alloc_frame()); 86 m_buffer_rgba .resize(avpicture_get_size(PIX_FMT_RGB32, width(), height()));87 m_buffer_rgba _public.resize(m_buffer_rgba.size());88 m_buffer_rgba[0].resize(avpicture_get_size(PIX_FMT_RGB32, width(), height())); 89 m_buffer_rgba[1].resize(m_buffer_rgba[0].size()); 88 90 89 91 // Assign appropriate parts of the buffer to image planes in m_frame_rgba 90 avpicture_fill((AVPicture *) m_frame_rgba.get(), &m_buffer_rgba[0], PIX_FMT_RGB32, width(), height());92 avpicture_fill((AVPicture *) (m_frame_rgba).get(), &(m_buffer_rgba[0])[0], PIX_FMT_RGB32, width(), height()); 91 93 92 94 // Override get_buffer()/release_buffer() from codec context in order to retrieve the PTS of each frame. … … 216 218 int src_pix_fmt, int src_width, int src_height) 217 219 { 220 osg::Timer_t startTick = osg::Timer::instance()->tick(); 218 221 #ifdef USE_SWSCALE 219 222 if (m_swscale_ctx==0) … … 221 224 m_swscale_ctx = sws_getContext(src_width, src_height, src_pix_fmt, 222 225 src_width, src_height, dst_pix_fmt, 223 SWS_BILINEAR, NULL, NULL, NULL);226 /*SWS_BILINEAR*/ SWS_BICUBIC, NULL, NULL, NULL); 224 227 } 225 228 226 osg::notify(osg::NOTICE)<<"Using sws_scale"<<std::endl; 227 228 return sws_scale(m_swscale_ctx, 229 src->data, src->linesize, 0, src_height, 230 dst->data, dst->linesize); 229 230 osg::notify(osg::NOTICE)<<"Using sws_scale "; 231 232 int result = sws_scale(m_swscale_ctx, 233 src->data, src->linesize, 0, src_height, 234 dst->data, dst->linesize); 231 235 #else 232 osg::notify(osg::NOTICE)<<"Using img_convert"<<std::endl; 233 234 return img_convert(dst, dst_pix_fmt, src, 235 src_pix_fmt, src_width, src_height); 236 237 osg::notify(osg::NOTICE)<<"Using img_convert "; 238 239 int result = img_convert(dst, dst_pix_fmt, src, 240 src_pix_fmt, src_width, src_height); 241 236 242 #endif 243 osg::Timer_t endTick = osg::Timer::instance()->tick(); 244 osg::notify(osg::NOTICE)<<" time = "<<osg::Timer::instance()->delta_m(startTick,endTick)<<"ms"<<std::endl; 245 246 return result; 237 247 } 238 248 … … 247 257 if (delay < -0.010) 248 258 return; 249 259 250 260 const AVPicture * const src = (const AVPicture *) m_frame.get(); 251 261 AVPicture * const dst = (AVPicture *) m_frame_rgba.get(); 262 263 osg::Timer_t startTick = osg::Timer::instance()->tick(); 264 265 // Assign appropriate parts of the buffer to image planes in m_frame_rgba 266 avpicture_fill((AVPicture *) (m_frame_rgba).get(), &(m_buffer_rgba[m_writeBuffer])[0], PIX_FMT_RGB32, width(), height()); 252 267 253 268 // Convert YUVA420p (i.e. YUV420p plus alpha channel) using our own routine … … 258 273 convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width(), height()); 259 274 275 260 276 // Flip and swap buffer 261 swapBuffers(); 277 // swapBuffers(); 278 279 280 osg::Timer_t endTick = osg::Timer::instance()->tick(); 281 osg::notify(osg::NOTICE)<<" time of swapBuffers = "<<osg::Timer::instance()->delta_m(startTick,endTick)<<"ms"<<std::endl; 262 282 263 283 // Wait 'delay' seconds before publishing the picture. … … 277 297 } 278 298 299 m_writeBuffer = 1-m_writeBuffer; 300 279 301 m_publish_func(* this, m_user_data); 280 302 } … … 285 307 { 286 308 for (int h = 0; h < height(); ++h) 287 memcpy(& m_buffer_rgba_public[(height() - h - 1) * width() * 4], &m_buffer_rgba[h * width() * 4], width() * 4);309 memcpy(&(m_buffer_rgba[1-m_writeBuffer])[(height() - h - 1) * width() * 4], &(m_buffer_rgba[m_writeBuffer])[h * width() * 4], width() * 4); 288 310 } 289 311
