Example #1
0
int CMediaInfo::GetVideoRotation(const wxString &filename)
{
	MediaInfo MI;
	wstring To_Display;
	MI.Open(CConvertUtility::ConvertToStdWstring(filename));
	To_Display = MI.Get(Stream_Video, 0, __T("Rotation"), Info_Text, Info_Name).c_str();
	MI.Close();
	if (To_Display != "")
		return std::stoi(To_Display);
	return 0;
}
void FilmInfoWindow::LoadTechnicalInfo( const QString& fileName )
{
    DebugPrintFunc( "FilmInfoWindow::LoadTechnicalInfo", fileName );
    QMutexLocker locker( &loadInfoMutex );

    MediaInfo* mi = new MediaInfo( fileName );
    emit FullInfoLoaded( mi->GetCompleteData() );
    delete mi;

    DebugPrintFuncDone( "FilmInfoWindow::LoadTechnicalInfo" );
}
Example #3
0
vector<CMetadata> CMediaInfo::ReadMetadata(const wxString &filename)
{
    vector<CMetadata> metadata;
    //Information about MediaInfo
    MediaInfo MI;
    String To_Display=MI.Option(__T("Info_Version"), __T("0.7.13;MediaInfoDLL_Example_MSVC;0.7.13")).c_str();
    MI.Open(CConvertUtility::ConvertToStdWstring(filename));
    std:wstring value = MI.Inform();
    metadata = SplitByLine(value);
    MI.Close();
    return metadata;
}
void MediaDecodeTask::OnMetadataRead(MetadataHolder&& aMetadata) {
  mMediaInfo = *aMetadata.mInfo;
  if (!mMediaInfo.HasAudio()) {
    mDecoderReader->Shutdown();
    ReportFailureOnMainThread(WebAudioDecodeJob::NoAudio);
    return;
  }

  nsCString codec;
  if (!mMediaInfo.mAudio.GetAsAudioInfo()->mMimeType.IsEmpty()) {
    codec = nsPrintfCString(
        "webaudio; %s", mMediaInfo.mAudio.GetAsAudioInfo()->mMimeType.get());
  } else {
    codec = nsPrintfCString("webaudio;resource; %s",
                            mContainerType.Type().AsString().Data());
  }

  nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
      "MediaDecodeTask::OnMetadataRead", [codec]() -> void {
        MOZ_ASSERT(!codec.IsEmpty());
        MOZ_LOG(gMediaDecoderLog, LogLevel::Debug,
                ("Telemetry (WebAudio) MEDIA_CODEC_USED= '%s'", codec.get()));
        Telemetry::Accumulate(Telemetry::HistogramID::MEDIA_CODEC_USED, codec);
      });
  SystemGroup::Dispatch(TaskCategory::Other, task.forget());

  RequestSample();
}
Example #5
0
void
MediaSourceReader::OnTrackBufferConfigured(TrackBuffer* aTrackBuffer, const MediaInfo& aInfo)
{
  ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
  MOZ_ASSERT(aTrackBuffer->IsReady());
  MOZ_ASSERT(mTrackBuffers.Contains(aTrackBuffer));
  if (aInfo.HasAudio() && !mAudioTrack) {
    MSE_DEBUG("MediaSourceReader(%p)::OnTrackBufferConfigured %p audio", this, aTrackBuffer);
    mAudioTrack = aTrackBuffer;
  }
  if (aInfo.HasVideo() && !mVideoTrack) {
    MSE_DEBUG("MediaSourceReader(%p)::OnTrackBufferConfigured %p video", this, aTrackBuffer);
    mVideoTrack = aTrackBuffer;
  }
  mDecoder->NotifyWaitingForResourcesStatusChanged();
}
Example #6
0
// CDLGMediaInfo message handlers
BOOL CDLGMediaInfo::OnInitDialog()
{
	CDialog::OnInitDialog();

	MediaInfo MI;

	MI.Open(path);
	MI.Option("Complete", "1");
	m_edit = MI.Inform().c_str();
	MI.Close();

	UpdateData(FALSE);


	return TRUE;  // return TRUE  unless you set the focus to a control
}
Example #7
0
void
MediaDecodeTask::OnMetadataRead(MetadataHolder* aMetadata)
{
  mMediaInfo = aMetadata->mInfo;
  if (!mMediaInfo.HasAudio()) {
    mDecoderReader->Shutdown();
    ReportFailureOnMainThread(WebAudioDecodeJob::NoAudio);
    return;
  }
  RequestSample();
}
Example #8
0
bool
MediaSourceDemuxer::ScanSourceBuffersForContent()
{
  MOZ_ASSERT(OnTaskQueue());

  if (mSourceBuffers.IsEmpty()) {
    return false;
  }

  MonitorAutoLock mon(mMonitor);

  bool haveEmptySourceBuffer = false;
  for (const auto& sourceBuffer : mSourceBuffers) {
    MediaInfo info = sourceBuffer->GetMetadata();
    if (!info.HasAudio() && !info.HasVideo()) {
      haveEmptySourceBuffer = true;
    }
    if (info.HasAudio() && !mAudioTrack) {
      mInfo.mAudio = info.mAudio;
      mAudioTrack = sourceBuffer;
    }
    if (info.HasVideo() && !mVideoTrack) {
      mInfo.mVideo = info.mVideo;
      mVideoTrack = sourceBuffer;
    }
    if (info.IsEncrypted() && !mInfo.IsEncrypted()) {
      mInfo.mCrypto = info.mCrypto;
    }
  }
  if (mInfo.HasAudio() && mInfo.HasVideo()) {
    // We have both audio and video. We can ignore non-ready source buffer.
    return true;
  }
  return !haveEmptySourceBuffer;
}
Example #9
0
SeekTask::SeekTask(const void* aDecoderID,
                   AbstractThread* aThread,
                   MediaDecoderReaderWrapper* aReader,
                   SeekJob&& aSeekJob,
                   const MediaInfo& aInfo,
                   const media::TimeUnit& aDuration,
                   int64_t aCurrentMediaTime)
  : mDecoderID(aDecoderID)
  , mOwnerThread(aThread)
  , mReader(aReader)
  , mSeekJob(Move(aSeekJob))
  , mCurrentTimeBeforeSeek(aCurrentMediaTime)
  , mAudioRate(aInfo.mAudio.mRate)
  , mHasAudio(aInfo.HasAudio())
  , mHasVideo(aInfo.HasVideo())
  , mDropAudioUntilNextDiscontinuity(false)
  , mDropVideoUntilNextDiscontinuity(false)
  , mIsDiscarded(false)
  , mIsAudioQueueFinished(false)
  , mIsVideoQueueFinished(false)
  , mNeedToStopPrerollingAudio(false)
  , mNeedToStopPrerollingVideo(false)
{
  // Bound the seek time to be inside the media range.
  int64_t end = aDuration.ToMicroseconds();
  NS_ASSERTION(end != -1, "Should know end time by now");
  int64_t seekTime = mSeekJob.mTarget.GetTime().ToMicroseconds();
  seekTime = std::min(seekTime, end);
  seekTime = std::max(int64_t(0), seekTime);
  NS_ASSERTION(seekTime >= 0 && seekTime <= end,
               "Can only seek in range [0,duration]");
  mSeekJob.mTarget.SetTime(media::TimeUnit::FromMicroseconds(seekTime));

  mDropAudioUntilNextDiscontinuity = HasAudio();
  mDropVideoUntilNextDiscontinuity = HasVideo();

  // Configure MediaDecoderReaderWrapper.
  SetMediaDecoderReaderWrapperCallback();
}
Example #10
0
AccurateSeekTask::AccurateSeekTask(const void* aDecoderID,
                                   AbstractThread* aThread,
                                   MediaDecoderReaderWrapper* aReader,
                                   const SeekTarget& aTarget,
                                   const MediaInfo& aInfo,
                                   const media::TimeUnit& aEnd,
                                   int64_t aCurrentMediaTime)
  : SeekTask(aDecoderID, aThread, aReader, aTarget)
  , mCurrentTimeBeforeSeek(media::TimeUnit::FromMicroseconds(aCurrentMediaTime))
  , mAudioRate(aInfo.mAudio.mRate)
  , mDoneAudioSeeking(!aInfo.HasAudio() || aTarget.IsVideoOnly())
  , mDoneVideoSeeking(!aInfo.HasVideo())
{
  AssertOwnerThread();

  // Bound the seek time to be inside the media range.
  NS_ASSERTION(aEnd.ToMicroseconds() != -1, "Should know end time by now");
  mTarget.SetTime(std::max(media::TimeUnit(), std::min(mTarget.GetTime(), aEnd)));

  // Configure MediaDecoderReaderWrapper.
  SetCallbacks();
}
BOOL CPPageFileMediaInfo::OnInitDialog()
{
	__super::OnInitDialog();

	if (!m_pCFont) {
		m_pCFont = DNew CFont;
	}

	if (!m_pCFont) {
		return TRUE;
	}

	MediaInfo MI;

	MI.Option(_T("ParseSpeed"), _T("0"));
	MI.Option(_T("Language"), mi_get_lang_file());
	MI.Option(_T("Complete"));
	MI.Open(m_fn.GetString());
	MI_Text = MI.Inform().c_str();
	MI.Close();

	if (!MI_Text.Find(_T("Unable to load"))) {
		MI_Text.Empty();
	}

	LOGFONT lf;
	memset(&lf, 0, sizeof(lf));
	lf.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN;

	LPCTSTR fonts[] = {_T("Consolas"), _T("Lucida Console"), _T("Courier New"), _T("") };

	UINT i = 0;
	BOOL success;

	PAINTSTRUCT ps;
	CDC* cDC = m_mediainfo.BeginPaint(&ps);

	do {
		wcscpy_s(lf.lfFaceName, LF_FACESIZE, fonts[i]);
		lf.lfHeight = -MulDiv(8, cDC->GetDeviceCaps(LOGPIXELSY), 72);
		success = IsFontInstalled(fonts[i]) && m_pCFont->CreateFontIndirect(&lf);
		i++;
	} while (!success && i < _countof(fonts));

	m_mediainfo.SetFont(m_pCFont);
	m_mediainfo.SetWindowText(MI_Text);

	m_mediainfo.EndPaint(&ps);

	OldControlProc = (WNDPROC)SetWindowLongPtr(m_mediainfo.m_hWnd, GWLP_WNDPROC, (LONG_PTR)ControlProc);

	return TRUE;
}
void
AudioSinkWrapper::Start(int64_t aStartTime, const MediaInfo& aInfo)
{
  AssertOwnerThread();
  MOZ_ASSERT(!mIsStarted, "playback already started.");

  mIsStarted = true;
  mPlayDuration = aStartTime;
  mPlayStartTime = TimeStamp::Now();

  // no audio is equivalent to audio ended before video starts.
  mAudioEnded = !aInfo.HasAudio();

  if (aInfo.HasAudio()) {
    mAudioSink = mCreator->Create();
    mEndPromise = mAudioSink->Init(mParams);

    mAudioSinkPromise.Begin(mEndPromise->Then(
      mOwnerThread.get(), __func__, this,
      &AudioSinkWrapper::OnAudioEnded,
      &AudioSinkWrapper::OnAudioEnded));
  }
}
Example #13
0
void XSPFParser::writeTrack(QXmlStreamWriter & xml, const MediaInfo & mediaInfo) {

	xml.writeStartElement(XSPF_TRACK);

		//Filename
		QUrl url(mediaInfo.fileName());
		writeTextElement(xml, XSPF_LOCATION, url.toEncoded());

		//Unique ID
		//FIXME not implemented yet
		//writeTextElement(xml, XSPF_IDENTIFIER, QString());

		//Artist
		writeTextElement(xml, XSPF_CREATOR, mediaInfo.metadataValue(MediaInfo::Artist));

		//Album
		writeTextElement(xml, XSPF_ALBUM, mediaInfo.metadataValue(MediaInfo::Album));

		//Track number
		writeTextElement(xml, XSPF_TRACKNUM, mediaInfo.metadataValue(MediaInfo::TrackNumber));

		//Title
		writeTextElement(xml, XSPF_TITLE, mediaInfo.metadataValue(MediaInfo::Title));

		//Comment
		writeTextElement(xml, XSPF_ANNOTATION, mediaInfo.metadataValue(MediaInfo::Comment));

		//Length
		writeIntElement(xml, XSPF_DURATION, mediaInfo.lengthMilliseconds());

		//Album art URL
		//FIXME not implemented yet
		//writeTextElement(xml, XSPF_IMAGE, mediaInfo.metadataValue(MediaInfo::AlbumArt));

		//URL of the original web page
		writeTextElement(xml, XSPF_INFO, mediaInfo.metadataValue(MediaInfo::URL));

		xml.writeStartElement(XSPF_EXTENSION);
		xml.writeAttribute(XSPF_APPLICATION, XSPF_QUARKPLAYER_NAMESPACE);
		writeTextElementWithNamespace(xml, XSPF_QUARKPLAYER_NAMESPACE, XSPF_QUARKPLAYER_CUE_START_INDEX, mediaInfo.cueStartIndexFormatted());
		writeTextElementWithNamespace(xml, XSPF_QUARKPLAYER_NAMESPACE, XSPF_QUARKPLAYER_CUE_END_INDEX, mediaInfo.cueEndIndexFormatted());
		writeTextElementWithNamespace(xml, XSPF_QUARKPLAYER_NAMESPACE, XSPF_QUARKPLAYER_YEAR, mediaInfo.metadataValue(MediaInfo::Year));
		writeTextElementWithNamespace(xml, XSPF_QUARKPLAYER_NAMESPACE, XSPF_QUARKPLAYER_GENRE, mediaInfo.metadataValue(MediaInfo::Genre));
		xml.writeEndElement();	//extension

	xml.writeEndElement();	//track
}
Example #14
0
void
VideoSink::Start(int64_t aStartTime, const MediaInfo& aInfo)
{
  AssertOwnerThread();
  VSINK_LOG("[%s]", __func__);

  mAudioSink->Start(aStartTime, aInfo);

  mHasVideo = aInfo.HasVideo();

  if (mHasVideo) {
    mEndPromise = mEndPromiseHolder.Ensure(__func__);
    ConnectListener();
    TryUpdateRenderedVideoFrames();
  }
}
Example #15
0
nsresult VideoSink::Start(const TimeUnit& aStartTime, const MediaInfo& aInfo) {
  AssertOwnerThread();
  VSINK_LOG("[%s]", __func__);

  nsresult rv = mAudioSink->Start(aStartTime, aInfo);

  mHasVideo = aInfo.HasVideo();

  if (mHasVideo) {
    mEndPromise = mEndPromiseHolder.Ensure(__func__);

    // If the underlying MediaSink has an end promise for the video track (which
    // happens when mAudioSink refers to a DecodedStream), we must wait for it
    // to complete before resolving our own end promise. Otherwise, MDSM might
    // stop playback before DecodedStream plays to the end and cause
    // test_streams_element_capture.html to time out.
    RefPtr<EndedPromise> p = mAudioSink->OnEnded(TrackInfo::kVideoTrack);
    if (p) {
      RefPtr<VideoSink> self = this;
      p->Then(mOwnerThread, __func__,
              [self]() {
                self->mVideoSinkEndRequest.Complete();
                self->TryUpdateRenderedVideoFrames();
                // It is possible the video queue size is 0 and we have no
                // frames to render. However, we need to call
                // MaybeResolveEndPromise() to ensure mEndPromiseHolder is
                // resolved.
                self->MaybeResolveEndPromise();
              },
              [self]() {
                self->mVideoSinkEndRequest.Complete();
                self->TryUpdateRenderedVideoFrames();
                self->MaybeResolveEndPromise();
              })
          ->Track(mVideoSinkEndRequest);
    }

    ConnectListener();
    // Run the render loop at least once so we can resolve the end promise
    // when video duration is 0.
    UpdateRenderedVideoFrames();
  }
  return rv;
}
Example #16
0
void
VideoSink::Start(int64_t aStartTime, const MediaInfo& aInfo)
{
  AssertOwnerThread();
  VSINK_LOG("[%s]", __func__);

  mAudioSink->Start(aStartTime, aInfo);

  mHasVideo = aInfo.HasVideo();

  if (mHasVideo) {
    mEndPromise = mEndPromiseHolder.Ensure(__func__);

    // If the underlying MediaSink has an end promise for the video track (which
    // happens when mAudioSink refers to a DecodedStream), we must wait for it
    // to complete before resolving our own end promise. Otherwise, MDSM might
    // stop playback before DecodedStream plays to the end and cause
    // test_streams_element_capture.html to time out.
    RefPtr<GenericPromise> p = mAudioSink->OnEnded(TrackInfo::kVideoTrack);
    if (p) {
      RefPtr<VideoSink> self = this;
      mVideoSinkEndRequest.Begin(p->Then(mOwnerThread, __func__,
        [self] () {
          self->mVideoSinkEndRequest.Complete();
          self->TryUpdateRenderedVideoFrames();
        }, [self] () {
          self->mVideoSinkEndRequest.Complete();
          self->TryUpdateRenderedVideoFrames();
        }));
    }

    ConnectListener();
    // Run the render loop at least once so we can resolve the end promise
    // when video duration is 0.
    UpdateRenderedVideoFrames();
  }
}
Example #17
0
int main (int argc, char *argv[])
{
    //Information about MediaInfo
    MediaInfo MI;
    ZenLib::Ztring To_Display=MI.Option(__T("Info_Version"), __T("0.7.0.0;MediaInfoDLL_Example_MSVC;0.7.0.0")).c_str();

    To_Display += __T("\r\n\r\nInfo_Parameters\r\n");
    To_Display += MI.Option(__T("Info_Parameters")).c_str();

    To_Display += __T("\r\n\r\nInfo_Capacities\r\n");
    To_Display += MI.Option(__T("Info_Capacities")).c_str();

    To_Display += __T("\r\n\r\nInfo_Codecs\r\n");
    To_Display += MI.Option(__T("Info_Codecs")).c_str();

    //An example of how to use the library
    To_Display += __T("\r\n\r\nOpen\r\n");
    MI.Open(__T("Example.ogg"));

    To_Display += __T("\r\n\r\nInform with Complete=false\r\n");
    MI.Option(__T("Complete"));
    To_Display += MI.Inform().c_str();

    To_Display += __T("\r\n\r\nInform with Complete=true\r\n");
    MI.Option(__T("Complete"), __T("1"));
    To_Display += MI.Inform().c_str();

    To_Display += __T("\r\n\r\nCustom Inform\r\n");
    MI.Option(__T("Inform"), __T("General;Example : FileSize=%FileSize%"));
    To_Display += MI.Inform().c_str();

    To_Display += __T("\r\n\r\nGet with Stream=General and Parameter=\"FileSize\"\r\n");
    To_Display += MI.Get(Stream_General, 0, __T("FileSize"), Info_Text, Info_Name).c_str();

    To_Display += __T("\r\n\r\nGetI with Stream=General and Parameter=46\r\n");
    To_Display += MI.Get(Stream_General, 0, 46, Info_Text).c_str();

    To_Display += __T("\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n");
    To_Display += ZenLib::Ztring::ToZtring(MI.Count_Get(Stream_Audio, -1)); //Warning : this is an integer

    To_Display += __T("\r\n\r\nGet with Stream=General and Parameter=\"AudioCount\"\r\n");
    To_Display += MI.Get(Stream_General, 0, __T("AudioCount"), Info_Text, Info_Name).c_str();

    To_Display += __T("\r\n\r\nGet with Stream=Audio and Parameter=\"StreamCount\"\r\n");
    To_Display += MI.Get(Stream_Audio, 0, __T("StreamCount"), Info_Text, Info_Name).c_str();

    To_Display += __T("\r\n\r\nClose\r\n");
    MI.Close();

    std::cout<<To_Display.To_Local().c_str()<<std::endl;

    return 0;
}
int main (int argc, MediaInfoLib::Char *argv[])
{
    //Information about MediaInfo
    MediaInfo MI;
    String To_Display=MI.Option(_T("Info_Version"), _T("0.7.0.0;MediaInfoDLL_Example_MSVC;0.7.0.0")).c_str();

    To_Display += _T("\r\n\r\nInfo_Parameters\r\n");
    To_Display += MI.Option(_T("Info_Parameters")).c_str();

    To_Display += _T("\r\n\r\nInfo_Capacities\r\n");
    To_Display += MI.Option(_T("Info_Capacities")).c_str();

    To_Display += _T("\r\n\r\nInfo_Codecs\r\n");
    To_Display += MI.Option(_T("Info_Codecs")).c_str();

    //An example of how to use the library
    To_Display += _T("\r\n\r\nOpen\r\n");
    MI.Open(_T("Example.ogg"));

    To_Display += _T("\r\n\r\nInform with Complete=false\r\n");
    MI.Option(_T("Complete"));
    To_Display += MI.Inform().c_str();

    To_Display += _T("\r\n\r\nInform with Complete=true\r\n");
    MI.Option(_T("Complete"), _T("1"));
    To_Display += MI.Inform().c_str();

    To_Display += _T("\r\n\r\nCustom Inform\r\n");
    MI.Option(_T("Inform"), _T("General;Example : FileSize=%FileSize%"));
    To_Display += MI.Inform().c_str();

    To_Display += _T("\r\n\r\nGet with Stream=General and Parameter=\"FileSize\"\r\n");
    To_Display += MI.Get(Stream_General, 0, _T("FileSize"), Info_Text, Info_Name).c_str();

    To_Display += _T("\r\n\r\nGetI with Stream=General and Parameter=46\r\n");
    To_Display += MI.Get(Stream_General, 0, 46, Info_Text).c_str();

    To_Display += _T("\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n");
    #ifdef __MINGW32__
        Char* C1=new Char[33];
        _itot (MI.Count_Get(Stream_Audio), C1, 10);
        To_Display +=C1;
        delete[] C1;
    #else
        toStringStream SS;
        SS << std::setbase(10) << MI.Count_Get(Stream_Audio);
        To_Display += SS.str();
    #endif

    To_Display += _T("\r\n\r\nGet with Stream=General and Parameter=\"AudioCount\"\r\n");
    To_Display += MI.Get(Stream_General, 0, _T("AudioCount"), Info_Text, Info_Name).c_str();

    To_Display += _T("\r\n\r\nGet with Stream=Audio and Parameter=\"StreamCount\"\r\n");
    To_Display += MI.Get(Stream_Audio, 0, _T("StreamCount"), Info_Text, Info_Name).c_str();

    To_Display += _T("\r\n\r\nClose\r\n");
    MI.Close();

    #ifdef _UNICODE
        std::wcout << To_Display;
    #else
        std::cout  << To_Display;
    #endif

    return 1;
}
Example #19
0
void CUEParser::load() {
	QTime timeElapsed;
	timeElapsed.start();

	_stop = false;

	QList<MediaInfo> files;

	qDebug() << __FUNCTION__ << "Playlist:" << _filename;

	//See http://regexlib.com/DisplayPatterns.aspx

	//REM GENRE "Alternative rock"
	//REM GENRE Pop
	static QRegExp rx_genre("^REM GENRE (.*)$");
	//REM DATE 1994
	static QRegExp rx_date("^REM DATE (\\d+)$");
	//PERFORMER "Weezer"
	static QRegExp rx_root_performer("^PERFORMER \"(.*)\"$");
	//TITLE "Weezer (The Blue Album)"
	static QRegExp rx_root_title("^TITLE \"(.*)\"$");
	//FILE "01. My Name Is Jonas - [Weezer] .wav" WAVE
	static QRegExp rx_file("^FILE \"(.*)\"");
	//  TRACK 01 AUDIO
	static QRegExp rx_track("^  TRACK (\\d+)");
	//    TITLE "No One Else"
	static QRegExp rx_title("^    TITLE \"(.*)\"$");
	//    PERFORMER "Weezer"
	static QRegExp rx_performer("^    PERFORMER \"(.*)\"$");
	//    INDEX 01 00:00:00
	static QRegExp rx_index("^    INDEX 01 (.*)$");

	QFile file(_filename);
	if (file.open(QIODevice::ReadOnly)) {
		QString path(QFileInfo(_filename).path());

		QTextStream stream(&file);

		MediaInfo mediaInfo;

		//Root elements
		QString genre;
		QString date;
		QString albumArtist;
		QString album;
		///

		QString filename;

		while (!stream.atEnd() && !_stop) {
			//Line of text, don't use trimmed()
			//since CUE sheet files contain indentation spaces
			QString line(stream.readLine());

			if (line.isEmpty()) {
				//Do nothing
			}

			else if (rx_genre.indexIn(line) != -1) {
				genre = rx_genre.cap(1);
			}

			else if (rx_date.indexIn(line) != -1) {
				date = rx_date.cap(1);
			}

			else if (rx_root_performer.indexIn(line) != -1) {
				albumArtist = rx_root_performer.cap(1);
			}

			else if (rx_root_title.indexIn(line) != -1) {
				album = rx_root_title.cap(1);
			}

			else if (rx_file.indexIn(line) != -1) {
				filename = rx_file.cap(1);
			}

			else if (rx_track.indexIn(line) != -1) {
				QString track(rx_track.cap(1));
				mediaInfo.insertMetadata(MediaInfo::TrackNumber, track);
			}

			else if (rx_title.indexIn(line) != -1) {
				QString title(rx_title.cap(1));
				mediaInfo.insertMetadata(MediaInfo::Title, title);
			}

			else if (rx_performer.indexIn(line) != -1) {
				QString performer(rx_performer.cap(1));
				mediaInfo.insertMetadata(MediaInfo::Artist, performer);
			}

			else if (rx_index.indexIn(line) != -1) {
				QString index(rx_index.cap(1));
				mediaInfo.setCueStartIndex(index);

				if (!files.isEmpty()) {
					//Now we know the CUE end index from the previous media
					files.last().setCueEndIndex(index);
				}

				mediaInfo.insertMetadata(MediaInfo::Genre, genre);
				mediaInfo.insertMetadata(MediaInfo::Year, date);
				mediaInfo.insertMetadata(MediaInfo::AlbumArtist, albumArtist);
				mediaInfo.insertMetadata(MediaInfo::Album, album);

				bool isUrl = MediaInfo::isUrl(filename);
				mediaInfo.setUrl(isUrl);
				if (isUrl) {
					mediaInfo.setFileName(filename);
				} else {
					mediaInfo.setFileName(Util::canonicalFilePath(path, filename));
				}

				if (!mediaInfo.fileName().isEmpty()) {
					//Add file to the list of files
					files << mediaInfo;

					//Clear the MediaInfo for the next lines
					mediaInfo.clear();

					if (files.size() > FILES_FOUND_LIMIT) {
						//Emits the signal every FILES_FOUND_LIMIT files found
						emit filesFound(files);
						files.clear();
					}
				}

			}

			else {
				//Syntax error
			}
		}
	}

	file.close();

	if (!files.isEmpty()) {
		//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
		emit filesFound(files);
	}

	//Emits the last signal
	emit finished(timeElapsed.elapsed());
}
Example #20
0
HRESULT get_mediainfo(const wchar_t *filename, media_info_entry **out, bool use_localization /* = false */)
{
	if (!out)
		return E_POINTER;

	MediaInfo MI;

	dwindow_log_line(L"Gettting MediaInfo for %s", filename);

	// localization
	if (use_localization)
	{
		wchar_t path[MAX_PATH];
		wcscpy(path, g_apppath);
		wcscat(path, C(L"MediaInfoLanguageFile"));

		FILE *f = _wfopen(path, L"rb");
		if (f)
		{
			wchar_t lang[102400] = L"";
			char tmp[1024];
			wchar_t tmp2[1024];
			USES_CONVERSION;
			while (fscanf(f, "%s", tmp, 1024, f) != EOF)
			{
				MultiByteToWideChar(CP_UTF8, 0, tmp, 1024, tmp2, 1024);

				if (wcsstr(tmp2, L";"))
				{
					wcscat(lang, tmp2);
					wcscat(lang, L"\n");
				}
			}
			fclose(f);
			MI.Option(_T("Language"), W2T(lang));
		}
		else
		{
			MI.Option(_T("Language"));
		}
	}
	else
	{
		MI.Option(_T("Language"));
	}

	MI.Open(filename);
	MI.Option(_T("Complete"));
	MI.Option(_T("Inform"));
	String str = MI.Inform().c_str();
	MI.Close();
	wchar_t *p = (wchar_t*)str.c_str();
	wchar_t *p2 = wcsstr(p, L"\n");
	wchar_t tmp[20480];
	bool next_is_a_header = true;

	media_info_entry *pm = *out = NULL;

	while (true)
	{
		if (p2)
		{
			p2[0] = NULL;
			p2 ++;
		}

		wcscpy(tmp, p);
		wcstrim(tmp);
		wcstrim(tmp, L'\n');
		wcstrim(tmp, L'\r');
		wcs_replace(tmp, L"  ", L" ");

		if (tmp[0] == NULL || tmp[0] == L'\n' || tmp[0] == L'\r')
		{
			next_is_a_header = true;
		}		
		else if (next_is_a_header)
		{
			next_is_a_header = false;

			if (NULL == pm)
				pm = *out = (media_info_entry*)calloc(1, sizeof(media_info_entry));
			else
				pm = pm->next = (media_info_entry*)calloc(1, sizeof(media_info_entry));



			wcscpy(pm->key, tmp);
			if (wcschr(pm->key, L':'))
			{
				*((wchar_t*)wcsrchr(pm->key, L':')) = NULL;

				wcscpy(pm->value, wcsrchr(tmp, L':')+1);
			}
			wcstrim(pm->key);
			wcstrim(pm->value);
			pm->level_depth = 0;
		}
		else
		{
			pm = pm->next = (media_info_entry*)calloc(1, sizeof(media_info_entry));

			wcscpy(pm->key, tmp);
			if (wcschr(pm->key, L':'))
			{
				*((wchar_t*)wcsrchr(pm->key, L':')) = NULL;

				wcscpy(pm->value, wcsrchr(tmp, L':')+1);
			}
			wcstrim(pm->key);
			wcstrim(pm->value);
			pm->level_depth = 1;
		}


		if (!p2)
			break;

		p = p2;
		p2 = wcsstr(p2, L"\n");
	}

	if(out)
	{
		dwindow_log_line(L"MediaInfo for %s", filename);
		for(media_info_entry *p = *out;p; p=p->next)
		{
			wchar_t space[] = L"          ";
			space[p->level_depth*2] = NULL;
			dwindow_log_line(L"%s %s - %s", space, p->key, p->value);
		}
	}

	return S_OK;
}
Example #21
0
HRESULT MediaInfoWindow::FillTree(HWND root, const wchar_t *filename)
{
	HTREEITEM file = InsertTreeviewItem(root, filename, TVI_ROOT);
	InsertTreeviewItem(root, C(L"Reading Infomation ...."), file);
	SendMessage(root, TVM_EXPAND, TVE_EXPAND, (LPARAM)file);
	DoEvents();

	MediaInfo MI;

	// language

	wchar_t path[MAX_PATH];
	wcscpy(path, g_apppath);
	wcscat(path, C(L"MediaInfoLanguageFile"));

	FILE *f = _wfopen(path, L"rb");
	if (f)
	{
		wchar_t lang[102400] = L"";
		char tmp[1024];
		wchar_t tmp2[1024];
		USES_CONVERSION;
		while (fscanf(f, "%s", tmp, 1024, f) != EOF)
		{
			MultiByteToWideChar(CP_UTF8, 0, tmp, 1024, tmp2, 1024);

			if (wcsstr(tmp2, L";"))
			{
				wcscat(lang, tmp2);
				wcscat(lang, L"\n");
			}
		}
		fclose(f);
		MI.Option(_T("Language"), W2T(lang));
	}
	else
	{
		MI.Option(_T("Language"));
	}

	HANDLE h_file = CreateFileW (filename, GENERIC_READ, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
	String str = L"";
	if (h_file != INVALID_HANDLE_VALUE)
	{
		__int64 filesize = 0;
		GetFileSizeEx(h_file, (LARGE_INTEGER*)&filesize);

		DWORD From_Buffer_Size = 0;
		unsigned char From_Buffer[1316];
		MI.Open_Buffer_Init(filesize);

		__int64 last_seek_target, seek_target = -5;

		do
		{
			if (seek_target >= 0)
				last_seek_target = seek_target;

			if (!ReadFile(h_file, From_Buffer, 1316, &From_Buffer_Size, NULL) || From_Buffer_Size <= 0)
				break;

			size_t result = MI.Open_Buffer_Continue(From_Buffer, From_Buffer_Size);
			if ((result&0x08)==0x08) // 8 = all done
				break;

			seek_target = MI.Open_Buffer_Continue_GoTo_Get();
			if (seek_target>=0)
				SetFilePointerEx(h_file, *(LARGE_INTEGER*)&seek_target, NULL, SEEK_SET);
			else if (seek_target >= filesize)
				break;
		}
		while (From_Buffer_Size>0 && last_seek_target != seek_target);
		MI.Open_Buffer_Finalize();

		MI.Option(_T("Complete"));
		MI.Option(_T("Inform"));
		str = MI.Inform().c_str();
		MI.Close();

		CloseHandle(h_file);
	}
	wchar_t *p = (wchar_t*)str.c_str();
	wchar_t *p2 = wcsstr(p, L"\n");
	wchar_t tmp[1024];
	bool next_is_a_header = true;
	
	//TreeView_DeleteAllItems (root);
	TreeView_DeleteItem(root, file);
	file = InsertTreeviewItem(root, filename, TVI_ROOT);
	wcscat(m_msg, filename);
	wcscat(m_msg, L"\r\n");
	HTREEITEM insert_position = file;
	HTREEITEM headers[4096] = {0};
	int headers_count = 0;

	wchar_t tbl[3][20]={L"\t", L"\t\t", L"\t\t\t"};

	while (true)
	{
		if (p2)
		{
			p2[0] = NULL;
			p2 ++;
		}
		
		wcscpy(tmp, p);
		wcstrim(tmp);
		wcstrim(tmp, L'\n');
		wcstrim(tmp, L'\r');
		wcs_replace(tmp, L"  ", L" ");

		if (tmp[0] == NULL || tmp[0] == L'\n' || tmp[0] == L'\r')
		{
			next_is_a_header = true;
		}		
		else if (next_is_a_header)
		{
			next_is_a_header = false;
			
			headers[headers_count++] = insert_position = InsertTreeviewItem(root, tmp, file);

			wcscat(m_msg, tbl[0]);
			wcscat(m_msg, tmp);
			wcscat(m_msg, L"\r\n");
		}
		else
		{
			InsertTreeviewItem(root, tmp, insert_position);
			wcscat(m_msg, tbl[1]);
			wcscat(m_msg, tmp);
			wcscat(m_msg, L"\r\n");
		}


		if (!p2)
			break;

		p = p2;
		p2 = wcsstr(p2, L"\n");
	}

	//add some items to the the tree view common control
	SendMessage(root, TVM_EXPAND, TVE_EXPAND, (LPARAM)file);
	for (int i=0; i<headers_count; i++)
		SendMessage(root, TVM_EXPAND, TVE_EXPAND, (LPARAM)headers[i]);

	TreeView_SelectItem (root, file);

	return S_OK;
}
Example #22
0
void XSPFParser::readTrack(QXmlStreamReader & xml, MediaInfo & mediaInfo) const {
	while (!xml.atEnd() && !_stop) {
		xml.readNext();

		QString element(xml.name().toString());

		if (xml.isStartElement()) {

			//Filename
			if (element == XSPF_LOCATION) {
				QUrl url = QUrl::fromEncoded(xml.readElementText().toUtf8());
				QString location(url.toString());
				bool isUrl = MediaInfo::isUrl(location);
				mediaInfo.setUrl(isUrl);
				if (isUrl) {
					mediaInfo.setFileName(location);
				} else {
					QString path(QFileInfo(_filename).path());
					mediaInfo.setFileName(Util::canonicalFilePath(path, location));
				}
			}

			//Unique ID
			else if (element == XSPF_IDENTIFIER) {
				QString identifier(xml.readElementText());
				//FIXME not implemented yet
			}

			//Artist
			else if (element == XSPF_CREATOR) {
				QString creator(xml.readElementText());
				mediaInfo.insertMetadata(MediaInfo::Artist, creator);
			}

			//Album
			else if (element == XSPF_ALBUM) {
				QString album(xml.readElementText());
				mediaInfo.insertMetadata(MediaInfo::Album, album);
			}

			//Track number
			else if (element == XSPF_TRACKNUM) {
				QString trackNum(xml.readElementText());
				mediaInfo.insertMetadata(MediaInfo::TrackNumber, trackNum);
			}

			//Title
			else if (element == XSPF_TITLE) {
				QString title(xml.readElementText());
				mediaInfo.insertMetadata(MediaInfo::Title, title);
			}

			//Comment
			else if (element == XSPF_ANNOTATION) {
				QString annotation(xml.readElementText());
				if (mediaInfo.metadataValue(MediaInfo::Title).isEmpty()) {
					//Some people didn't understand how XSPF works
					//and confused annotation with title
					mediaInfo.insertMetadata(MediaInfo::Title, annotation);
				}
				mediaInfo.insertMetadata(MediaInfo::Comment, annotation);
			}

			//Length
			else if (element == XSPF_DURATION) {
				int duration = xml.readElementText().toInt();
				//XSPF gives us the duration in milliseconds
				//Let's convert it to seconds
				mediaInfo.setLength(duration / 1000);
			}

			//Album art URL
			else if (element == XSPF_IMAGE) {
				QString image(xml.readElementText());
				//FIXME not implemented yet
				//mediaInfo.insertMetadata(MediaInfo::AlbumArt, image);
			}

			//URL of the original web page
			else if (element == XSPF_INFO) {
				QString info(xml.readElementText());
				mediaInfo.insertMetadata(MediaInfo::URL, info);
			}

			//Meta
			else if (element == XSPF_META) {

				//These tags are specific to foobar2000 XSPF plugin

				QXmlStreamAttributes attributes = xml.attributes();

				//Date
				if (attributes.hasAttribute(XSPF_FOOBAR2000_DATE)) {
					QString date(attributes.value(XSPF_FOOBAR2000_DATE).toString());
					mediaInfo.insertMetadata(MediaInfo::Year, date);
				}

				//Genre
				else if (attributes.hasAttribute(XSPF_FOOBAR2000_GENRE)) {
					QString genre(attributes.value(XSPF_FOOBAR2000_GENRE).toString());
					mediaInfo.insertMetadata(MediaInfo::Genre, genre);
				}
			}

			else if (element == XSPF_EXTENSION) {
				QString xspfNamespace(xml.attributes().value(XSPF_APPLICATION).toString());

				if (xspfNamespace == XSPF_QUARKPLAYER_NAMESPACE) {
					while (!xml.atEnd() && !_stop) {
						xml.readNext();

						QString extensionElement(xml.name().toString());
						if (xml.isStartElement()) {

							if (extensionElement == XSPF_QUARKPLAYER_CUE_START_INDEX) {
								QString cueStartIndex(xml.readElementText());
								mediaInfo.setCueStartIndex(cueStartIndex);
							}

							else if (extensionElement == XSPF_QUARKPLAYER_CUE_END_INDEX) {
								QString cueEndIndex(xml.readElementText());
								mediaInfo.setCueEndIndex(cueEndIndex);
							}

							else if (extensionElement == XSPF_QUARKPLAYER_YEAR) {
								QString year(xml.readElementText());
								mediaInfo.insertMetadata(MediaInfo::Year, year);
							}

							else if (extensionElement == XSPF_QUARKPLAYER_GENRE) {
								QString genre(xml.readElementText());
								mediaInfo.insertMetadata(MediaInfo::Genre, genre);
							}
						}

						if (xml.isEndElement()) {
							if (extensionElement == XSPF_EXTENSION) {
								break;
							}
						}
					}
				}
			}
		}

		if (xml.isEndElement()) {
			if (element == XSPF_TRACK) {
				return;
			}
		}
	}
}
void NBMediaInfoModel::setupModel() {

	MediaInfo MI;
	MI.Open( FromQString( mFileName ) );

	QStringList keys;
	for( int s = (int)Stream_General; s < (int)Stream_Max; s++ ) {
		size_t streamNumMax = MI.Count_Get( (stream_t)s );
		if ( not streamNumMax )
			continue;

		for( size_t j = 0; j < streamNumMax; j++ ) {
			QString streamKindName = FromZString( MI.Get( (stream_t)s, j, ZString( "StreamKind/String" ), Info_Text ) );
			if ( streamNumMax > 1 )
				streamKindName += QString( " %1" ).arg( j );

			size_t infoCount = MI.Count_Get( (stream_t)s, j );

			if ( not infoCount )
				continue;

			NBMediaInfoNode *streamNode = new NBMediaInfoNode( streamKindName, QString(), rootNode );

			keys.clear();
			for( size_t i = 0; i < infoCount; i++ ) {
				QString name = FromZString( MI.Get( (stream_t)s, j, i, Info_Name_Text ) );
				QString value = FromZString( MI.Get( (stream_t)s, j, i, Info_Text ) );

				if ( name.contains( "Count", Qt::CaseInsensitive ) )
					continue;

				else if ( name.contains( "name", Qt::CaseInsensitive ) and not name.contains( "track", Qt::CaseInsensitive ) )
					continue;

				else if ( name.startsWith( "Kind of", Qt::CaseInsensitive ) )
					continue;

				else if ( name == "File size" )
					continue;

				else if ( name.contains( "last modification", Qt::CaseInsensitive ) )
					continue;

				else if ( name.contains( "Extensions usually", Qt::CaseInsensitive ) )
					continue;

				if ( value.size() )
					 value += FromZString( MI.Get( (stream_t)s, 0, i, Info_Measure_Text ) );

				if ( not name.size() or not value.size() )
					continue;

				if ( not keys.contains( name ) ) {
					keys << name;
					streamNode->addChild( new NBMediaInfoNode( name, value, streamNode ) );
				}
			}

			rootNode->addChild( streamNode );
		}
	}

	mQuickInfo = FromZString( MI.Inform() );
};
Example #24
0
void M3UParser::load() {
	QTime timeElapsed;
	timeElapsed.start();

	_stop = false;

	QList<MediaInfo> files;

	qDebug() << __FUNCTION__ << "Playlist:" << _filename;

	//See http://regexlib.com/DisplayPatterns.aspx

	//#EXTM3U
	static QRegExp rx_extm3u("^#EXTM3U$|^#M3U$");
	//#EXTINF:123,Sample title
	static QRegExp rx_extinf("^#EXTINF:([-+]?\\d+),(.*)$");
	//#EXTINF:Sample title
	static QRegExp rx_extinf_title("^#EXTINF:(.*)$");
	//#Just a comment
	static QRegExp rx_comment("^#.*$");

	QFile file(_filename);
	if (file.open(QIODevice::ReadOnly)) {
		QString path(QFileInfo(_filename).path());

		QTextStream stream(&file);

		if (isUtf8()) {
			stream.setCodec("UTF-8");
		} else {
			stream.setCodec(QTextCodec::codecForLocale());
		}

		MediaInfo mediaInfo;

		while (!stream.atEnd() && !_stop) {
			//Line of text excluding '\n'
			QString line(stream.readLine().trimmed());

			if (line.isEmpty()) {
				//Do nothing
			}

			else if (rx_extm3u.indexIn(line) != -1) {
				//#EXTM3U line, ignored
			}

			else if (rx_extinf.indexIn(line) != -1) {
				//#EXTINF line
				QString length(rx_extinf.cap(1));
				if (!length.isEmpty()) {
					mediaInfo.setLength(length.toInt());
				}
				QString title(rx_extinf.cap(2));
				if (!title.isEmpty()) {
					mediaInfo.insertMetadata(MediaInfo::Title, title);
				}
			}

			else if (rx_extinf_title.indexIn(line) != -1) {
				QString title(rx_extinf_title.cap(1));
				if (!title.isEmpty()) {
					mediaInfo.insertMetadata(MediaInfo::Title, title);
				}
			}

			else if (rx_comment.indexIn(line) != -1) {
				//# line, comment, ignored
			}

			else {
				bool isUrl = MediaInfo::isUrl(line);
				mediaInfo.setUrl(isUrl);
				if (isUrl) {
					mediaInfo.setFileName(line);
				} else {
					mediaInfo.setFileName(Util::canonicalFilePath(path, line));
				}

				//Add file to the list of files
				files << mediaInfo;

				//Clear the MediaInfo for the next 2 lines from the m3u playlist
				mediaInfo.clear();

				if (files.size() > FILES_FOUND_LIMIT) {
					//Emits the signal every FILES_FOUND_LIMIT files found
					emit filesFound(files);
					files.clear();
				}
			}
		}
	}

	file.close();

	if (!files.isEmpty()) {
		//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
		emit filesFound(files);
	}

	//Emits the last signal
	emit finished(timeElapsed.elapsed());
}
void RegressionTest_Events(Ztring Files, Ztring DataBaseDirectory, int32u Scenario)
{
    // Scenarios:
    // bit  0 : quick parsing / full parsing
    // bit  1 : next packet interface
    // bit  2 : demux (by container only)
    // bit  3 : do some seeks


    cout<<" Analyzing"<<endl;
    ZtringListListF FilesList_Source;
    if (FileName(Files).Extension_Get()==__T("csv"))
        FilesList_Source.Load(DataBaseDirectory+__T("\\Events\\FilesList.csv"));
    else
    {
        if (File::Exists(Files))
            FilesList_Source.push_back(Files);
        else
            FilesList_Source.push_back(Files+__T("\\*.*"));
    }
    vector<Events_UserHandle_struct> FilesList;
    for (size_t FilesList_Source_Pos=0; FilesList_Source_Pos<FilesList_Source.size(); FilesList_Source_Pos++)
    {
        ZtringList Temp=Dir::GetAllFileNames(FilesList_Source[FilesList_Source_Pos](0));
        for (size_t Temp_Pos=0; Temp_Pos<Temp.size(); Temp_Pos++)
        {
            struct Events_UserHandle_struct ToAdd;
            ToAdd.Name=Temp[Temp_Pos];
            ToAdd.DataBaseDirectory=DataBaseDirectory;
            ToAdd.Files=Files;
            ToAdd.Scenario=Scenario;
            if (Scenario&(1<<0))
                ToAdd.ParseSpeed=true;
            if (Scenario&(1<<1))
                ToAdd.NextPacket=true;
            if (Scenario&(1<<2))
                ToAdd.DemuxContainerOnly=true;
            if (Scenario&(1<<3))
                ToAdd.Seek=true;

            FilesList.push_back(ToAdd);
        }
    }


    for (size_t FilesList_Pos=0; FilesList_Pos<FilesList.size(); FilesList_Pos++)
    {
        cout<<" "<<FilesList_Pos+1<<"/"<<FilesList.size()<<" "<<FilesList[FilesList_Pos].Name.To_Local()<<endl;

        MediaInfo MI;
        Ztring MI_Result;

        //**********************************************************************
        // Configuring
        //**********************************************************************

        // CallBack configuration
        // MediaInfo need pointer as text (for compatibility with older version) + 64-bit OS handling
        // form is "CallBack=memory://handlerInDecimal;UserHandler=memory://handlerInDecimal"
        // UserHandler is a unique value wich will be provided to the callback function, in order to know which MediaInfo instance send the event
        wostringstream Event_CallBackFunction_Text;
        Event_CallBackFunction_Text<<__T("CallBack=memory://")<<(MediaInfo_int64u)Event_CallBackFunction<<__T(";UserHandler=memory://")<<(MediaInfo_int64u)&FilesList[FilesList_Pos];
        MI_Result=MI.Option(__T("File_Event_CallBackFunction"), Event_CallBackFunction_Text.str());
        if (!MI_Result.empty())
        {
            wcout<<__T("MediaInfo error: ")<<MI_Result<<endl;
            return;
        }

        //Retrieiving basic data
        MI.Open(FilesList[FilesList_Pos].Name);
        Ztring Delay_10s=Ztring().Duration_From_Milliseconds(Ztring(MI.Get(Stream_Video, 0, __T("Delay"))).To_int64u()+10000);

        if (FilesList[FilesList_Pos].ParseSpeed)
        {
            MI_Result=MI.Option(__T("ParseSpeed"), __T("1.0"));
            if (!MI_Result.empty())
            {
                wcout<<__T("MediaInfo error: ")<<MI_Result<<endl;
                return;
            }
        }

        if (FilesList[FilesList_Pos].DemuxContainerOnly)
        {
            MI_Result=MI.Option(__T("Demux"), __T("container"));
            if (!MI_Result.empty())
            {
                wcout<<__T("MediaInfo error: ")<<MI_Result<<endl;
                return;
            }

            MI_Result=MI.Option(__T("File_Demux_Unpacketize"), __T("1"));
            if (!MI_Result.empty())
            {
                wcout<<__T("MediaInfo error: ")<<MI_Result<<endl;
                return;
            }

            MI_Result=MI.Option(__T("File_Demux_PCM_20bitTo16bit"), __T("1"));
            if (!MI_Result.empty())
            {
                wcout<<__T("MediaInfo error: ")<<MI_Result<<endl;
                return;
            }
        }

        if (FilesList[FilesList_Pos].NextPacket)
        {
            MI_Result=MI.Option(__T("File_NextPacket"), __T("1"));
            if (!MI_Result.empty())
            {
                wcout<<__T("MediaInfo error: ")<<MI_Result<<endl;
                return;
            }
        }

        MI.Open(FilesList[FilesList_Pos].Name);

        if (FilesList[FilesList_Pos].NextPacket)
        {
            int Counter=0;
            while (MI.Open_NextPacket()&0x100)
            {
                if (FilesList[FilesList_Pos].Seek)
                {
                    Counter++;
                    if (Counter==0)
                        MI.Option(__T("File_Seek"), __T("0"));
                    if (Counter==100)
                        MI.Option(__T("File_Seek"), Delay_10s);
                    if (Counter==200)
                        MI.Option(__T("File_Seek"), __T("Frame=100"));
                    if (Counter==300)
                        MI.Option(__T("File_Seek"), __T("95%"));
                }
            }
        }

        FilesList[FilesList_Pos].Clear();
    }

    cout<<" Diff"<<endl;
    ZtringList Ref=Dir::GetAllFileNames(DataBaseDirectory+__T("\\Events\\Ref\\")+FileName(Files).Name_Get()+__T("\\")+Ztring::ToZtring(Scenario)+__T("*.*"));
    ZtringList New=Dir::GetAllFileNames(DataBaseDirectory+__T("\\Events\\New\\")+FileName(Files).Name_Get()+__T("\\")+Ztring::ToZtring(Scenario)+__T("*.*"));
    for (size_t Ref_Pos=0; Ref_Pos<Ref.size(); Ref_Pos++)
    {
        Ztring Ref_ToFind=Ref[Ref_Pos];
        Ref_ToFind.FindAndReplace(__T("\\Events\\Ref\\"), __T("\\Events\\New\\"));
        size_t New_RefPos=New.Find(Ref_ToFind);
        bool IsDiff=false;
        if (New_RefPos!=(size_t)-1)
        {
            File F_Ref; F_Ref.Open(Ref[Ref_Pos]);
            File F_New; F_New.Open(New[New_RefPos]);
            if (F_Ref.Size_Get()==F_New.Size_Get())
            {
                int64u Size=F_Ref.Size_Get();
                if (Size>100000000)
                    Size=100000000;
                int8u* F_Ref_Buffer=new int8u[(size_t)Size];
                F_Ref.Read(F_Ref_Buffer, (size_t)Size);
                int8u* F_New_Buffer=new int8u[(size_t)Size];
                F_New.Read(F_New_Buffer, (size_t)Size);

                if (memcmp(F_Ref_Buffer, F_New_Buffer, (size_t)Size))
                    IsDiff=true;

                delete[] F_Ref_Buffer;
                delete[] F_New_Buffer;
            }
            else
                IsDiff=true;
        }
        if (New_RefPos==(size_t)-1 || IsDiff)
        {
            //Not in new or is different
            Ztring Diff_Name=Ref[Ref_Pos];
            Diff_Name.FindAndReplace(__T("\\Events\\Ref\\"), __T("\\Events\\Diff\\"));
            if (!Dir::Exists(DataBaseDirectory+__T("\\Events\\Diff")))
                Dir::Create(DataBaseDirectory+__T("\\Events\\Diff"));
            if (!Dir::Exists(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get()))
                Dir::Create(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get());
            if (!Dir::Exists(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get()+__T("\\")+Ztring::ToZtring(Scenario)))
                Dir::Create(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get()+__T("\\")+Ztring::ToZtring(Scenario));
            if (!Dir::Exists(FileName(Diff_Name).Path_Get()))
                Dir::Create(FileName(Diff_Name).Path_Get());
            if (!IsDiff)
                File::Copy(Ref[Ref_Pos], Diff_Name+__T(".RefAlone.txt")); //Not in new
            else
            {
                File::Copy(Ref[Ref_Pos], Diff_Name+__T(".Ref.txt")); //Diff
                File::Copy(New[New_RefPos], Diff_Name+__T(".New.txt"));
            }
        }
        if (New_RefPos!=(size_t)-1)
            New.erase(New.begin()+New_RefPos);
    }
    for (size_t New_Pos=0; New_Pos<New.size(); New_Pos++)
    {
        //Not in ref
        Ztring Diff_Name=New[New_Pos];
        Diff_Name.FindAndReplace(__T("\\Events\\New\\"), __T("\\Events\\Diff\\"));
        if (!Dir::Exists(DataBaseDirectory+__T("\\Events\\Diff")))
            Dir::Create(DataBaseDirectory+__T("\\Events\\Diff"));
        if (!Dir::Exists(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get()))
            Dir::Create(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get());
        if (!Dir::Exists(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get()+__T("\\")+Ztring::ToZtring(Scenario)))
            Dir::Create(DataBaseDirectory+__T("\\Events\\Diff\\")+FileName(Files).Name_Get()+__T("\\")+Ztring::ToZtring(Scenario));
        if (!Dir::Exists(FileName(Diff_Name).Path_Get()))
            Dir::Create(FileName(Diff_Name).Path_Get());
         File::Copy(New[New_Pos], Diff_Name+__T(".NewAlone.txt")); //Not in new
    }
}
Example #26
0
void XSPFParser::load() {
	QTime timeElapsed;
	timeElapsed.start();

	_stop = false;

	QList<MediaInfo> files;

	qDebug() << __FUNCTION__ << "Playlist:" << _filename;

	QFile file(_filename);
	if (file.open(QIODevice::ReadOnly)) {
		MediaInfo mediaInfo;

		QXmlStreamReader xml(&file);
		while (!xml.atEnd() && !_stop) {
			xml.readNext();

			switch (xml.tokenType()) {

			case QXmlStreamReader::StartElement: {
				QString element(xml.name().toString());

				if (element == XSPF_TRACK) {
					readTrack(xml, mediaInfo);

					if (!mediaInfo.fileName().isEmpty()) {
						//Add file to the list of files
						files << mediaInfo;

						//Clear the MediaInfo
						mediaInfo.clear();

						if (files.size() > FILES_FOUND_LIMIT) {
							//Emits the signal every FILES_FOUND_LIMIT files found
							emit filesFound(files);
							files.clear();
						}
					}
				}

				//Otherwise won't read the track end element
				break;
			}

			}
		}

		if (xml.hasError()) {
			qCritical() << __FUNCTION__ << "Error:" << xml.errorString()
				<< "line:" << xml.lineNumber()
				<< "column:" << xml.columnNumber();
		}
	}

	file.close();

	if (!files.isEmpty()) {
		//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
		emit filesFound(files);
	}

	//Emits the last signal
	emit finished(timeElapsed.elapsed());
}