diff --git a/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.cpp b/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.cpp index f0383069..764625a6 100644 --- a/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.cpp +++ b/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.cpp @@ -22,6 +22,8 @@ * Created on: Jul 28, 2013 * Author: aclarke */ +#include +#include #include "DecoderTest.h" #include @@ -31,6 +33,8 @@ #include #include +VS_LOG_SETUP(VS_CPP_PACKAGE.DecoderTest); + DecoderTest::DecoderTest() { } @@ -337,3 +341,65 @@ DecoderTest::testOpenCloseMP4() { } source->close(); } +void +DecoderTest::testIssue27() +{ + const char* testURL="http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8"; + RefPointer demuxer = Demuxer::make(); + + RefPointer decoder; + int32_t decoderIndex = -1; + try { + demuxer->open(testURL, 0, true, false, 0, 0); + demuxer->queryStreamMetaData(); + int32_t n = demuxer->getNumStreams(); + // loop through until we find our first video stream. + for(int32_t i = 0; i < n; ++i) { + RefPointer stream = demuxer->getStream(i); + decoder = stream->getDecoder(); + if (decoder->getCodecType() == MediaDescriptor::MEDIA_VIDEO) { + decoderIndex = i; + break; + } + decoder = 0; + } + } catch (std::exception & e) { + // if we catch an error, just return. that's not the focus of this test, and it will fail if the URL or network is down. + return; + } + if (!decoder.value()) + return; + + // now let's decode some number of frames. + int32_t frames = 150; + int32_t frameNo = 0; + RefPointer packet = MediaPacket::make(); + RefPointer picture = MediaPicture::make( + decoder->getWidth(), + decoder->getHeight(), + decoder->getPixelFormat()); + + decoder->open(0, 0); + while(demuxer->read(packet.value()) >= 0 && frameNo < frames) { + // got a packet; now we try to decode it. + if (packet->getStreamIndex() == decoderIndex && + packet->isComplete()) { + int32_t bytesRead = 0; + int32_t byteOffset=0; + do { + bytesRead = decoder->decodeVideo(picture.value(), packet.value(), byteOffset); + if (picture->isComplete()) { + TS_ASSERT_DIFFERS(Global::NO_PTS, picture->getPacketDts()); + TS_ASSERT_DIFFERS(Global::NO_PTS, picture->getPacketPts()); + TS_ASSERT_DIFFERS(Global::NO_PTS, picture->getTimeStamp()); + VS_LOG_DEBUG("Writing frame: %"PRId32, frameNo); + writePicture("DecoderTest_testIssue27", &frameNo, picture.value()); + ++frameNo; + } + byteOffset += bytesRead; + } while(byteOffset < packet->getSize()); + } + } + + demuxer->close(); +} diff --git a/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.h b/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.h index bae05a14..128e827a 100644 --- a/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.h +++ b/humble-video-native/src/main/gnu/test/io/humble/video/DecoderTest.h @@ -46,6 +46,7 @@ class DecoderTest : public CxxTest::TestSuite void testDecodeAudio(); void testDecodeVideo(); void testOpenCloseMP4(); + void testIssue27(); private: void writeAudio(FILE* output, MediaAudio* audio); void writePicture(const char* prefix, int32_t* frameNo, MediaPicture* picture);