| 316 | } |
| 317 | |
| 318 | static int encode_frame( unsigned char *inBuf, int width, int height ) |
| 319 | { |
| 320 | int luma_size = width * height; |
| 321 | int chroma_size = luma_size / 4; |
| 322 | int i_frame_size = 0; |
| 323 | int ofs; |
| 324 | unsigned int flags = 0; |
| 325 | |
| 326 | ofs = 0; |
| 327 | memcpy( pic.img.plane[0], &inBuf[ofs], luma_size ); ofs += luma_size; |
| 328 | memcpy( pic.img.plane[1], &inBuf[ofs], chroma_size ); ofs += chroma_size; |
| 329 | memcpy( pic.img.plane[2], &inBuf[ofs], chroma_size ); ofs += chroma_size; |
| 330 | |
| 331 | pic.i_pts = i_frame++; |
| 332 | |
| 333 | i_frame_size = x264_encoder_encode( hdl, &nal, &i_nal, &pic, &pic_out ); |
| 334 | |
| 335 | if ( i_frame_size < 0 ) |
| 336 | { |
| 337 | return -1; |
| 338 | } |
| 339 | else if ( i_frame_size ) |
| 340 | { |
| 341 | if ( pic_out.b_keyframe ) |
| 342 | { |
| 343 | flags |= gwavi_t::IF_KEYFRAME; |
| 344 | } |
| 345 | gwavi->add_frame( nal->p_payload, i_frame_size, flags ); |
| 346 | } |
| 347 | return i_frame_size; |
| 348 | } |
| 349 | |
| 350 | static int close(void) |
| 351 | { |