示例#1
0
void
CodecTest :: testEncodePCM()
{
  codec = Codec::findEncodingCodecByName("pcm_s16le");
  TSM_ASSERT("", codec);
  TSM_ASSERT("", codec->canEncode());
}
void
MediaPacketTest::testGetDefaults() {
  packet = MediaPacket::make();
  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);

}
示例#3
0
void
CodecTest :: testHasCapability()
{
  codec = Codec::findEncodingCodecByName("nellymoser");
  TSM_ASSERT("got codec", codec);
  int32_t capabilities = codec->getCapabilities();
  TSM_ASSERT("this codec has some set", capabilities != 0);
  TSM_ASSERT("should have delay set", 
      codec->hasCapability(Codec::CAP_DELAY));
}
示例#4
0
void
CodecTest :: testGetSupportedAudioSampleRates()
{
  codec = Codec::findEncodingCodecByName("nellymoser");
  TSM_ASSERT("got codec", codec);
  int32_t num= codec->getNumSupportedAudioSampleRates();
  TSM_ASSERT("no one supports this yet", num == 0);
  TSM_ASSERT("should fail quietly",
      codec->getSupportedAudioSampleRate(-1)==0);
  TSM_ASSERT("should fail quietly", 
      codec->getSupportedAudioSampleRate(0x7FFFFFFF)==0);
}
示例#5
0
void
CodecTest :: testCreationAndDescruction()
{
  codec = Codec::findDecodingCodec(Codec::CODEC_ID_NELLYMOSER);
  TSM_ASSERT("could not find NELLYMOSER decoder", codec);

  codec = Codec::findEncodingCodec(Codec::CODEC_ID_MP3);
  TSM_ASSERT("could not find MP3 encoder", codec);

  // should not find these.
  codec = Codec::findEncodingCodec(Codec::CODEC_ID_RV40);
  TSM_ASSERT("could find Real Audio encoder, but we thought FFMPEG couldn't support that", !codec);

}
示例#6
0
void Read3DDataTest::TestReadMultiSliceFile()
{
    TSM_ASSERT( "Images (from multi slice file) are not equal.", ReadAndCompare( 
        "/Data/Tests/DcmAPI/synthetic/colors/axial/color-a1.dcm",
        "/Data/Tests/DcmAPI/synthetic/colors/axial/color-a1.vtk",
        FILE ) );
}
示例#7
0
void Read3DDataTest::TestReadDicomDir()
{
    TSM_ASSERT( "Images (from DICOMDIR) are not equal.", ReadAndCompare( 
        "/Data/Tests/DcmAPI/synthetic/colors/axial/files/DICOMDIR",
        "/Data/Tests/DcmAPI/synthetic/colors/axial/color-a1.vtk",
        DICOMDIR ) );
}
示例#8
0
void Read3DDataTest::TestReadDirectory()
{
    TSM_ASSERT( "Images (from folder) are not equal.", ReadAndCompare( 
        "/Data/Tests/DcmAPI/synthetic/colors/axial/files",
        "/Data/Tests/DcmAPI/synthetic/colors/axial/color-a1.vtk",
        FOLDER ) );
}
示例#9
0
void Read3DDataTest::TestReadSingleSliceFile()
{
    TSM_ASSERT( "Images (from single slice file) are not equal.", ReadAndCompare( 
        "/Data/Tests/DcmAPI/synthetic/colors/axial/files/color-a1_000.dcm",
        "/Data/Tests/DcmAPI/synthetic/colors/axial/color-a1_000.vtk",
        FILE ) );
}
示例#10
0
void
CodecTest :: testGetSupportedVideoPixelFormats()
{
  codec = Codec::findEncodingCodecByName("ffvhuff");
  TSM_ASSERT("got codec", codec);
  int32_t num= codec->getNumSupportedVideoPixelFormats();
  TSM_ASSERT("should be more than one", num > 0);
  for(int i = 0; i < num; i++)
  {
    PixelFormat::Type type = codec->getSupportedVideoPixelFormat(i);
    TSM_ASSERT("should be non null", type != PixelFormat::PIX_FMT_NONE);
  }
  TSM_ASSERT("should fail quietly",
      PixelFormat::PIX_FMT_NONE == codec->getSupportedVideoPixelFormat(-1));
  TSM_ASSERT("should fail quietly",
      PixelFormat::PIX_FMT_NONE == codec->getSupportedVideoPixelFormat(0x7FFFFFFF));
}
示例#11
0
void
CodecTest :: testGetSupportedAudioChannelLayouts()
{
  codec = Codec::findEncodingCodecByName("ac3");
  TSM_ASSERT("got codec", codec);
  int32_t num= codec->getNumSupportedAudioChannelLayouts();
  TSM_ASSERT("should be more than none", num > 0);
  for(int i = 0; i < num; i++)
  {
    int64_t layout = codec->getSupportedAudioChannelLayout(i);
    TSM_ASSERT("should be non null", 0 != layout);
  }
  TSM_ASSERT("should fail quietly",
      0 == codec->getSupportedAudioChannelLayout(-1));
  TSM_ASSERT("should fail quietly",
      0 == codec->getSupportedAudioChannelLayout(0x7FFFFFFF));
}
示例#12
0
void
CodecTest :: testGetSupportedAudioSampleFormats()
{
  codec = Codec::findDecodingCodecByName("aac");
  TSM_ASSERT("got codec", codec);
  int32_t num= codec->getNumSupportedAudioFormats();
  TSM_ASSERT("should be more than none", num > 0);
  for(int i = 0; i < num; i++)
  {
    AudioFormat::Type fmt = codec->getSupportedAudioFormat(i);
    TSM_ASSERT("should be non null", fmt != AudioFormat::SAMPLE_FMT_NONE);
  }
  TSM_ASSERT("should fail quietly",
      AudioFormat::SAMPLE_FMT_NONE == codec->getSupportedAudioFormat(-1));
  TSM_ASSERT("should fail quietly",
      AudioFormat::SAMPLE_FMT_NONE == codec->getSupportedAudioFormat(0x7FFFFFFF));
}
示例#13
0
void
CodecTest :: testInvalidArguments()
{
  // should not find these.
  codec = Codec::findEncodingCodecByName(0);
  TSM_ASSERT("could find null encoder", !codec);

  codec = Codec::findEncodingCodecByName("");
  TSM_ASSERT("could find empty encoder", !codec);

  codec = Codec::findDecodingCodecByName(0);
  TSM_ASSERT("could find null Decoder", !codec);

  codec = Codec::findDecodingCodecByName("");
  TSM_ASSERT("could find empty Decoder", !codec);

}
示例#14
0
void
CodecTest :: testGuessEncodingCodecs()
{
  // should not find these.
  codec = Codec::guessEncodingCodec(0, 0, "file.mov", 0,
      MediaDescriptor::MEDIA_VIDEO);
  TSM_ASSERT("could not find mpeg4 codec", codec);
  codec = Codec::guessEncodingCodec(0, 0, "file.flv", 0,
      MediaDescriptor::MEDIA_VIDEO);
  TSM_ASSERT("could not find flv codec", codec);
  codec = Codec::guessEncodingCodec(0, 0, "file.flv", 0,
      MediaDescriptor::MEDIA_AUDIO);
  TSM_ASSERT("could not find flv codec", codec);
  codec = Codec::guessEncodingCodec(0, 0, 0, 0,
      MediaDescriptor::MEDIA_AUDIO);
  TSM_ASSERT("could find codec", !codec);

}
示例#15
0
void
CodecTest :: testFindByName()
{
  codec = Codec::findDecodingCodecByName("nellymoser");
  TSM_ASSERT("could not find NELLYMOSER decoder", codec);

  codec = Codec::findEncodingCodecByName("libmp3lame");
  TSM_ASSERT("could not find MP3 encoder", codec);


  // should not find these.
  codec = Codec::findEncodingCodecByName("xan_wc3");
  TSM_ASSERT("could find xan_wc3 encoder", !codec);

  codec = Codec::findDecodingCodecByName("adts");
  TSM_ASSERT("could find ADTS Decoder", !codec);

}
示例#16
0
void
CodecTest :: testGetInstalledCodecs()
{
  LoggerStack stack;
  stack.setGlobalLevel(Logger::LEVEL_INFO, false);

  int num = Codec::getNumInstalledCodecs();
  TSM_ASSERT("should be > 1", num > 1);
  for(int i = 0; i < num; i++)
  {
    codec = Codec::getInstalledCodec(i);
    TSM_ASSERT("should be valid", codec);
    if (codec) {
      VS_LOG_DEBUG("%s: %s",
          codec->getName(), codec->getLongName());
    }
  }
  TSM_ASSERT("could fail quietly",
      0 == Codec::getInstalledCodec(-1));
  TSM_ASSERT("could fail quietly",
      0 == Codec::getInstalledCodec(0x7FFFFFFF));
}
示例#17
0
void
CodecTest :: testGetSupportedVideoFramRates()
{
  codec = Codec::findEncodingCodecByName("mpeg2video");
  TSM_ASSERT("got codec", codec);
  int32_t numFrameRates = codec->getNumSupportedVideoFrameRates();
  TSM_ASSERT("should be more than one", numFrameRates > 0);
  for(int i = 0; i < numFrameRates; i++)
  {
    RefPointer<Rational> rate = codec->getSupportedVideoFrameRate(i);
    TSM_ASSERT("should be non null", rate);
    TSM_ASSERT("should be valid number", rate->getDouble());
  }
  TSM_ASSERT("should fail quietly",
      0 == codec->getSupportedVideoFrameRate(-1));
  TSM_ASSERT("should fail quietly",
      0 == codec->getSupportedVideoFrameRate(0x7FFFFFFF));
  
}
示例#18
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);
    }
  }
}
示例#19
0
bool Read3DDataTest::ReadAndCompare( 
    const std::string& dcmInputNameEnd, 
    const std::string& vtkFileNameEnd,
    const TYPE& inputType ) const
{
	try
	{
        // Working directory of the test
        const std::string dcmInputName = std::string(CISTIB_TOOLKIT_FOLDER) + dcmInputNameEnd;
        const std::string vtkFileName = std::string(CISTIB_TOOLKIT_FOLDER) + vtkFileNameEnd;

         // Check if the vtk file exists
        std::ifstream ifs2( vtkFileName.c_str() );
        TSM_ASSERT( "The input VTK file does not exist.", !ifs2.fail() );
        if( ifs2.fail() ) return false;
        ifs2.close();

        // read input
        vtkSmartPointer<vtkImageData> vtkDicomImage;
        switch( inputType )
        {
            case FILE:
            {
                // Check if the dicom file exists
                std::ifstream ifs1( dcmInputName.c_str() );
                TSM_ASSERT( "The input DICOM file does not exist.", !ifs1.fail() );
                if( ifs1.fail() ) return false;
                ifs1.close();
                // Read using dcmAPI::ImageUtilities
                vtkDicomImage = dcmAPI::ImageUtilities::ReadVtkImageFromFile< unsigned short, 3 >( 
                    dcmInputName.c_str(), true );
            }
            break;
            
            case FOLDER:
            {
                // Check if the folder exists
                if ( !boost::filesystem::exists( dcmInputName ) ) return false;
                // create list of files
                std::vector< std::string > dcmFileNames;
                boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
                for( boost::filesystem::directory_iterator itr( dcmInputName );
                    itr != end_itr; ++itr )
                {
                    if( is_regular_file(itr->status()) && itr->leaf() != "DICOMDIR")
                    {
                        dcmFileNames.push_back( dcmInputName + "/" + itr->leaf() );
                    }
                }
                // sort the files alphabetically
                std::sort(dcmFileNames.begin(), dcmFileNames.end());
                // Read using dcmAPI::ImageUtilities
                vtkDicomImage = dcmAPI::ImageUtilities::ReadMultiSliceVtkImageFromFiles< unsigned short, 3 >( 
                    dcmFileNames, true );
           }
            break;
            
            case DICOMDIR:
            {
		        // Data set
		        dcmAPI::DataSet::Pointer dcmData = dcmAPI::DataSet::New();
		        
		        // scan the current working folder for dicom files
		        dcmAPI::DataSetReader::Pointer reader = dcmAPI::DataSetReader::New( );
		        reader->SetDataSet( dcmData );
		        reader->ReadDicomDir( dcmInputName ); 
		        
		        // Patient
			    const dcmAPI::Patient::Pointer patient = dcmData->GetPatient( dcmData->GetPatientIds()->at(0) );
		        // Study
		        const dcmAPI::Study::Pointer study = patient->Study( patient->StudyIds()->at(0) );
		        // Serie
		        const dcmAPI::Series::Pointer series = study->Series( study->SeriesIds()->at(0) );
		        // TimePoint
		        const dcmAPI::TimePoint::Pointer timePoint = series->TimePoint( series->TimePointIds()->at(0) );
		        // Slice
		        const dcmAPI::SliceIdVectorPtr sliceIdVector = timePoint->SliceIds();
		        std::vector< std::string > dcmFileNames;
		        for( unsigned int i=0; i < sliceIdVector->size(); ++i)
		        {
			        const dcmAPI::Slice::Pointer slice = timePoint->Slice(sliceIdVector->at(i));
			        const std::string filePath = slice->GetTagAsText(dcmAPI::tags::SliceFilePath);
			        dcmFileNames.push_back( filePath );
			    }
                // Read using dcmAPI::ImageUtilities
                vtkDicomImage = dcmAPI::ImageUtilities::ReadMultiSliceVtkImageFromFiles< unsigned short, 3 >( 
                    dcmFileNames, true );
            }
            break;
            
            default:
            {
                TS_FAIL("Read3DDataTest::ReadAndCompare failed: unknwown case.");
		        return false;
            }
        }
        
        // Read using BaseLib
        vtkSmartPointer<vtkImageData> vtkImage = blImageUtils::LoadImageFromFileAsVTK( vtkFileName.c_str() );

        // Compare image content
        return blImageUtils::CompareImages( vtkDicomImage, vtkImage, 1e-5 );
	}
	catch(...)
	{
		TS_FAIL("Read3DDataTest::ReadAndCompare failed: thrown exception.");
		return false;
	}
}
示例#20
0
void
MediaPacketTest::testCreationAndDestruction() {
  packet = MediaPacket::make();
  TSM_ASSERT("was able to allocate packet", packet);
}