| 253 | } |
| 254 | |
| 255 | Result RecordFrame(HRecorder recorder, const void* frame_buffer, |
| 256 | uint32_t frame_buffer_size, BufferFormat format) |
| 257 | { |
| 258 | vpx_codec_iter_t iter = NULL; |
| 259 | const vpx_codec_cx_pkt_t *pkt; |
| 260 | vpx_codec_err_t res; |
| 261 | int flags = 0; |
| 262 | |
| 263 | RGBAToYV12((const uint8_t*) frame_buffer, recorder->m_Width, recorder->m_Height, recorder->m_VpxImage.planes[0], recorder->m_VpxImage.planes[1], recorder->m_VpxImage.planes[2]); |
| 264 | res = vpx_codec_encode(&recorder->m_Codec, &recorder->m_VpxImage, recorder->m_FrameCount, 1, flags, VPX_DL_REALTIME); |
| 265 | if (res) |
| 266 | { |
| 267 | dmLogError("Failed to encode frame (%s)", vpx_codec_err_to_string(res)) |
| 268 | return RESULT_UNKNOWN_ERROR; |
| 269 | } |
| 270 | |
| 271 | while ((pkt = vpx_codec_get_cx_data(&recorder->m_Codec, &iter))) |
| 272 | { |
| 273 | switch (pkt->kind) |
| 274 | { |
| 275 | case VPX_CODEC_CX_FRAME_PKT: |
| 276 | if (!WriteIvfFrameHeader(recorder, pkt)) |
| 277 | { |
| 278 | return RESULT_IO_ERROR; |
| 279 | } |
| 280 | |
| 281 | if (fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, |
| 282 | recorder->m_File) != pkt->data.frame.sz) |
| 283 | { |
| 284 | return RESULT_IO_ERROR; |
| 285 | } |
| 286 | break; |
| 287 | default: |
| 288 | break; |
| 289 | } |
| 290 | } |
| 291 | recorder->m_FrameCount++; |
| 292 | |
| 293 | return RESULT_OK; |
| 294 | } |
| 295 | } |