| 324 | } |
| 325 | |
| 326 | bool decoderLibde265::decodeFrame() |
| 327 | { |
| 328 | int more = 1; |
| 329 | curImage = nullptr; |
| 330 | while (more && curImage == nullptr) |
| 331 | { |
| 332 | more = 0; |
| 333 | auto err = this->lib.de265_decode(this->decoder, &more); |
| 334 | |
| 335 | if (err == DE265_ERROR_WAITING_FOR_INPUT_DATA) |
| 336 | { |
| 337 | this->decoderState = DecoderState::NeedsMoreData; |
| 338 | return false; |
| 339 | } |
| 340 | else if (err != DE265_OK) |
| 341 | return setErrorB("Error decoding (de265_decode)"); |
| 342 | |
| 343 | this->curImage = this->lib.de265_get_next_picture(this->decoder); |
| 344 | } |
| 345 | |
| 346 | if (more == 0 && curImage == nullptr) |
| 347 | { |
| 348 | // Decoding ended |
| 349 | this->decoderState = DecoderState::EndOfBitstream; |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | if (curImage != nullptr) |
| 354 | { |
| 355 | // Get the resolution / yuv format from the frame |
| 356 | auto s = Size(this->lib.de265_get_image_width(curImage, 0), |
| 357 | this->lib.de265_get_image_height(curImage, 0)); |
| 358 | if (!s.isValid()) |
| 359 | DEBUG_LIBDE265("decoderLibde265::decodeFrame got invalid frame size"); |
| 360 | auto subsampling = convertFromInternalSubsampling(this->lib.de265_get_chroma_format(curImage)); |
| 361 | if (subsampling == video::yuv::Subsampling::UNKNOWN) |
| 362 | DEBUG_LIBDE265("decoderLibde265::decodeFrame got invalid subsampling"); |
| 363 | auto bitDepth = functions::clipToUnsigned(this->lib.de265_get_bits_per_pixel(curImage, 0)); |
| 364 | if (bitDepth < 8 || bitDepth > 16) |
| 365 | DEBUG_LIBDE265("decoderLibde265::decodeFrame got invalid bit depth"); |
| 366 | |
| 367 | if (!this->frameSize.isValid() && !this->formatYUV.isValid()) |
| 368 | { |
| 369 | // Set the values |
| 370 | this->frameSize = s; |
| 371 | this->formatYUV = video::yuv::PixelFormatYUV(subsampling, bitDepth); |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | // Check the values against the previously set values |
| 376 | if (this->frameSize != s) |
| 377 | return setErrorB("Received a frame of different size"); |
| 378 | if (this->formatYUV.getSubsampling() != subsampling) |
| 379 | return setErrorB("Received a frame with different subsampling"); |
| 380 | if (this->formatYUV.getBitsPerSample() != bitDepth) |
| 381 | return setErrorB("Received a frame with different bit depth"); |
| 382 | } |
| 383 | DEBUG_LIBDE265("decoderLibde265::decodeFrame Picture decoded"); |
no test coverage detected