void PacketTest :: testCopyPacket() { packet = IPacket::make(); VS_TUT_ENSURE("was able to allocate packet", packet); // everything else should be garbage. int64_t position = packet->getPosition(); VS_TUT_ENSURE("position was not set to -1", position == -1); position = 4; packet->setPosition(position); int64_t dts = 28349762; packet->setDts(dts); int64_t pts = 82729373; packet->setPts(pts); RefPointer<IRational> timeBase = IRational::make(3,28972); packet->setTimeBase(timeBase.value()); int32_t streamIndex = 8; packet->setStreamIndex(streamIndex); int64_t duration = 28387728; packet->setDuration(duration); int64_t convergenceDuration = 283; packet->setConvergenceDuration(convergenceDuration); // Now, make a copy RefPointer<IPacket> newPacket = IPacket::make(packet.value(), false); VS_TUT_ENSURE("should not be empty", newPacket); VS_TUT_ENSURE_EQUALS("should equal", position, newPacket->getPosition()); VS_TUT_ENSURE_EQUALS("should equal", pts, newPacket->getPts()); VS_TUT_ENSURE_EQUALS("should equal", dts, newPacket->getDts()); VS_TUT_ENSURE_EQUALS("should equal", streamIndex, newPacket->getStreamIndex()); VS_TUT_ENSURE_EQUALS("should equal", duration, newPacket->getDuration()); VS_TUT_ENSURE_EQUALS("should equal", convergenceDuration, newPacket->getConvergenceDuration()); RefPointer<IRational> newBase = newPacket->getTimeBase(); VS_TUT_ENSURE("should be equal", newBase->compareTo(timeBase.value()) == 0); }
void MediaPacketTest::testCopyPacket() { const int32_t size = 512; packet = MediaPacket::make(size); TSM_ASSERT("was able to allocate packet", packet); // everything else should be garbage. int64_t position = packet->getPosition(); TSM_ASSERT("position was not set to -1", position == -1); position = 4; packet->setPosition(position); int64_t dts = 28349762; packet->setDts(dts); int64_t pts = 82729373; packet->setPts(pts); RefPointer<Rational> timeBase = Rational::make(3, 28972); packet->setTimeBase(timeBase.value()); int32_t streamIndex = 8; packet->setStreamIndex(streamIndex); int64_t duration = 28387728; packet->setDuration(duration); int64_t convergenceDuration = 283; packet->setConvergenceDuration(convergenceDuration); // let's get access to the data RefPointer<Buffer> data = packet->getData(); TS_ASSERT_EQUALS(size+16, data->getBufferSize()); TS_ASSERT_EQUALS(size, packet->getSize()); uint8_t* raw = (uint8_t*) data->getBytes(0, size); for (int i = 0; i < size; i++) raw[i] = i % 16; // Now, make a copy bool tests[] = { true, false }; for (size_t i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++) { RefPointer<MediaPacket> newPacket = MediaPacket::make(packet.value(), tests[i]); TSM_ASSERT("should not be empty", newPacket); // let's make sure that when not copying, the data is the same. TSM_ASSERT_EQUALS("should equal", position, newPacket->getPosition()); TSM_ASSERT_EQUALS("should equal", pts, newPacket->getPts()); TSM_ASSERT_EQUALS("should equal", dts, newPacket->getDts()); TSM_ASSERT_EQUALS("should equal", streamIndex, newPacket->getStreamIndex()); TSM_ASSERT_EQUALS("should equal", duration, newPacket->getDuration()); TSM_ASSERT_EQUALS("should equal", convergenceDuration, newPacket->getConvergenceDuration()); RefPointer<Rational> newBase = newPacket->getTimeBase(); TSM_ASSERT("should be equal", newBase->compareTo(timeBase.value()) == 0); RefPointer<Buffer> buf = newPacket->getData(); TS_ASSERT_EQUALS(size, newPacket->getSize()); TS_ASSERT_EQUALS(size+16, buf->getBufferSize()); uint8_t* d = (uint8_t*) buf->getBytes(0, size); if (!tests[i]) { TS_ASSERT_EQUALS(d, raw); } else { TS_ASSERT_DIFFERS(d, raw); } TS_ASSERT(d); for (int j = 0; j < size; j++) { TS_ASSERT_EQUALS(d[j], j % 16); } } }
void StreamCoderTest :: testGetters() { int refcount=0; h->setupReading(h->SAMPLE_FILE); for(int i = 0; i< h->num_streams; i++) { RefPointer<IStream> stream; RefPointer<ICodec> codec; RefPointer<IRational> rational; stream = h->streams[i]; coder = h->coders[i]; VS_TUT_ENSURE_EQUALS("invalid direction", coder->getDirection(), IStreamCoder::DECODING); codec = coder->getCodec(); refcount = codec->getCurrentRefCount(); { LoggerStack stack; stack.setGlobalLevel(Logger::LEVEL_ERROR, false); coder->setCodec(codec.value()); } // ensure that one release and one acquire happens VS_TUT_ENSURE_EQUALS("invalid releasing or acquiring of codec", codec->getCurrentRefCount(), refcount); VS_TUT_ENSURE_EQUALS("wrong codec type", codec->getType(), h->expected_codec_types[i]); VS_TUT_ENSURE_EQUALS("wrong codec id", codec->getID(), h->expected_codec_ids[i]); if (codec->getType() == ICodec::CODEC_TYPE_AUDIO) { if (h->expected_sample_rate) VS_TUT_ENSURE_EQUALS("unexpected sample rate", coder->getSampleRate(), h->expected_sample_rate ); if (h->expected_channels) VS_TUT_ENSURE_EQUALS("unexpected sample rate", coder->getChannels(), h->expected_channels ); } else if (codec->getType() == ICodec::CODEC_TYPE_VIDEO) { if (h->expected_width) VS_TUT_ENSURE_EQUALS("unexpected width", coder->getWidth(), h->expected_width ); if (h->expected_height) VS_TUT_ENSURE_EQUALS("unexpected height", coder->getHeight(), h->expected_height ); if (h->expected_gops) VS_TUT_ENSURE_EQUALS("unexpected group of pictures", coder->getNumPicturesInGroupOfPictures(), h->expected_gops ); if (h->expected_pixel_format != IPixelFormat::NONE) VS_TUT_ENSURE_EQUALS("unexpected group of pictures", coder->getPixelType(), h->expected_pixel_format ); if (h->expected_time_base) { rational = coder->getTimeBase(); VS_TUT_ENSURE_DISTANCE("unexpected time base", rational->getDouble(), h->expected_time_base, 0.0001 ); rational = stream->getTimeBase(); VS_TUT_ENSURE_DISTANCE("unexpected time base", rational->getDouble(), h->expected_time_base, 0.0001 ); } } else { VS_LOG_ERROR("Unexpected type of codec"); TS_ASSERT(false); } } }