Return the decoded data back to the parent.
| 1054 | |
| 1055 | // Return the decoded data back to the parent. |
| 1056 | void Decode_m (GMPVideoEncodedFrame* inputFrame, |
| 1057 | SBufferInfo* decoded, |
| 1058 | unsigned char* data[3], |
| 1059 | int64_t renderTimeMs, |
| 1060 | bool valid) { |
| 1061 | // Attach a self-destructor so that this dies on return. |
| 1062 | SelfDestruct<GMPVideoEncodedFrame> ifd (inputFrame); |
| 1063 | |
| 1064 | // If we don't actually have data, just abort. |
| 1065 | if (!valid) { |
| 1066 | GMPLOG (GL_ERROR, "No valid data decoded"); |
| 1067 | Error (GMPDecodeErr); |
| 1068 | return; |
| 1069 | } |
| 1070 | |
| 1071 | if (decoded->iBufferStatus != 1) { |
| 1072 | GMPLOG (GL_ERROR, "iBufferStatus=" << decoded->iBufferStatus); |
| 1073 | if (callback_) { |
| 1074 | callback_->InputDataExhausted(); |
| 1075 | } |
| 1076 | return; |
| 1077 | } |
| 1078 | |
| 1079 | int width = decoded->UsrData.sSystemBuffer.iWidth; |
| 1080 | int height = decoded->UsrData.sSystemBuffer.iHeight; |
| 1081 | int ystride = decoded->UsrData.sSystemBuffer.iStride[0]; |
| 1082 | int uvstride = decoded->UsrData.sSystemBuffer.iStride[1]; |
| 1083 | |
| 1084 | GMPLOG (GL_DEBUG, "Video frame ready for display " |
| 1085 | << width |
| 1086 | << "x" |
| 1087 | << height |
| 1088 | << " timestamp=" |
| 1089 | << inputFrame->TimeStamp()); |
| 1090 | |
| 1091 | GMPVideoFrame* ftmp = nullptr; |
| 1092 | |
| 1093 | if (!host_) { |
| 1094 | return; |
| 1095 | } |
| 1096 | |
| 1097 | // Translate the image. |
| 1098 | GMPErr err = host_->CreateFrame (kGMPI420VideoFrame, &ftmp); |
| 1099 | if (err != GMPNoErr) { |
| 1100 | GMPLOG (GL_ERROR, "Couldn't allocate empty I420 frame"); |
| 1101 | return; |
| 1102 | } |
| 1103 | |
| 1104 | |
| 1105 | GMPVideoi420Frame* frame = static_cast<GMPVideoi420Frame*> (ftmp); |
| 1106 | err = frame->CreateFrame ( |
| 1107 | ystride * height, static_cast<uint8_t*> (data[0]), |
| 1108 | uvstride * height / 2, static_cast<uint8_t*> (data[1]), |
| 1109 | uvstride * height / 2, static_cast<uint8_t*> (data[2]), |
| 1110 | width, height, |
| 1111 | ystride, uvstride, uvstride); |
| 1112 | if (err != GMPNoErr) { |
| 1113 | GMPLOG (GL_ERROR, "Couldn't make decoded frame"); |