| 382 | } |
| 383 | |
| 384 | IAFFrame *pixelBufferConvertor::convert(IAFFrame *frame) |
| 385 | { |
| 386 | auto *avAFFrame = dynamic_cast<AVAFFrame *>(frame); |
| 387 | if (avAFFrame == nullptr) { |
| 388 | return nullptr; |
| 389 | } |
| 390 | |
| 391 | if (mVideoInfo != frame->getInfo().video) { |
| 392 | int ret = init(frame->getInfo().video); |
| 393 | if (ret < 0) { |
| 394 | AF_LOGE("convert init error %d\n", ret); |
| 395 | return nullptr; |
| 396 | } |
| 397 | mVideoInfo = frame->getInfo().video; |
| 398 | } |
| 399 | auto *avFrame = (AVFrame *) (*avAFFrame); |
| 400 | |
| 401 | VideoColorInfo colorInfo; |
| 402 | colorInfo.chroma_location = static_cast<AFChromaLocation>(avFrame->chroma_location); |
| 403 | colorInfo.color_primaries = static_cast<AFColorPrimaries>(avFrame->color_primaries); |
| 404 | colorInfo.color_range = static_cast<AFColorRange>(avFrame->color_range); |
| 405 | colorInfo.color_space = static_cast<AFColorSpace>(avFrame->colorspace); |
| 406 | colorInfo.color_trc = static_cast<AFColorTransferCharacteristic>(avFrame->color_trc); |
| 407 | |
| 408 | if (sws_ctx) { |
| 409 | sws_scale(sws_ctx, avFrame->data, avFrame->linesize, 0, avFrame->height, mOutFrame->data, mOutFrame->linesize); |
| 410 | avFrame = mOutFrame; |
| 411 | } |
| 412 | |
| 413 | CVPixelBufferRef pixelBuffer = avFrame2pixelBuffer(avFrame); |
| 414 | if (pixelBuffer == nullptr) { |
| 415 | return nullptr; |
| 416 | } |
| 417 | |
| 418 | UpdateColorInfo(colorInfo, pixelBuffer); |
| 419 | auto *pBFrame = new PBAFFrame(pixelBuffer, frame->getInfo().pts, frame->getInfo().duration, colorInfo); |
| 420 | pBFrame->getInfo().video = frame->getInfo().video; |
| 421 | pBFrame->getInfo().video.format = AF_PIX_FMT_APPLE_PIXEL_BUFFER; |
| 422 | CFRelease(pixelBuffer); |
| 423 | return pBFrame; |
| 424 | } |
| 425 | void pixelBufferConvertor::UpdateColorInfo(const VideoColorInfo &info, CVPixelBufferRef pixelBuffer) |
| 426 | { |
| 427 | #if TARGET_OS_IPHONE |