Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
SubtitlesMicroDVD.cpp
Package: Visual C++视频音频开发实用工程案例精选.rar [view]
Upload User: tuheem
Upload Date: 2007-05-01
Package Size: 21889k
Code Size: 4k
Category:
Multimedia Develop
Development Platform:
Visual C++
- /**************************************************************************************
- * *
- * *
- **************************************************************************************/
- #include "SubtitlesMicroDVD.h"
- MediaSubtitlerMicroDVD::MediaSubtitlerMicroDVD()
- {
- this->inputFile = new MediaInput();
- this->inputBuffer = new MediaBuffer();
- }
- MediaSubtitlerMicroDVD::~MediaSubtitlerMicroDVD()
- {
- delete this->inputFile;
- delete this->inputBuffer;
- }
- media_type_t MediaSubtitlerMicroDVD::GetType()
- {
- return MEDIA_TYPE_SUBTITLER;
- }
- char *MediaSubtitlerMicroDVD::GetName()
- {
- return "MicroDVD Subtitle Reader";
- }
- MP_RESULT MediaSubtitlerMicroDVD::Connect(MediaItem *item)
- {
- return MP_RESULT_OK;
- }
- MP_RESULT MediaSubtitlerMicroDVD::ReleaseConnections()
- {
- return MP_RESULT_OK;
- }
- DWORD MediaSubtitlerMicroDVD::GetCaps()
- {
- return 0;
- }
- MP_RESULT MediaSubtitlerMicroDVD::Configure(HINSTANCE hInstance, HWND hwnd)
- {
- return MP_RESULT_ERROR;
- }
- MP_RESULT MediaSubtitlerMicroDVD::ParseSubtitle()
- {
- char text[512];
- DWORD i, j, count;
- if( sscanf((char *) this->inputBuffer->GetData(), "{%d}{%d}", &this->firstFrame, &this->lastFrame) != 2)
- return MP_RESULT_ERROR;
- strcpy(text, strrchr((char *) this->inputBuffer->GetData(), '}') + 1);
- i = 0;
- count = 0;
- for(j=0; j < strlen(text); j++) {
- if(text[j] == '|') {
- this->subtitles.subtitlesText[i][count] = '';
- i++;
- count = 0;
- }
- else {
- if(text[j] == 'n') {
- this->subtitles.subtitlesText[i][count] = '';
- break;
- }
- else {
- this->subtitles.subtitlesText[i][count] = text[j];
- count++;
- }
- }
- }
- this->subtitles.nbSubtitles = i + 1;
- return MP_RESULT_OK;
- }
- MP_RESULT MediaSubtitlerMicroDVD::SeekToFrame(DWORD frameNumber)
- {
- if(frameNumber > this->lastFrame) {
- do {
- this->inputFile->GetLine(this->inputBuffer);
- this->previousLastFrame = this->lastFrame;
- if(sscanf((char *) this->inputBuffer->GetData(), "{%d}{%d}", &this->firstFrame, &this->lastFrame) != 2) {
- return MP_RESULT_ERROR;
- }
- }
- while(this->firstFrame < frameNumber);
- this->ParseSubtitle();
- }
- else {
- this->inputFile->Seek(0, INPUT_SEEK_SET);
- this->firstFrame = 0;
- this->lastFrame = 0;
- this->previousLastFrame = 0;
- SeekToFrame(frameNumber);
- }
- return MP_RESULT_OK;
- }
- MP_RESULT MediaSubtitlerMicroDVD::Open(char *lpFilename)
- {
- if(lpFilename) {
- this->firstFrame = 0;
- this->lastFrame = 0;
- this->firstSubtitleFrame = 0;
- this->previousLastFrame = 0;
- if(this->inputFile->Open(lpFilename, INPUT_OPEN_ASCII) == MP_RESULT_OK) {
- this->inputBuffer->Alloc(SUB_INPUT_BUFFER_SIZE);
- this->subtitles.subtitlesText[0] = (char *) new char[256];
- this->subtitles.subtitlesText[1] = (char *) new char[256];
- this->subtitles.subtitlesText[2] = (char *) new char[256];
- this->subtitles.subtitlesText[3] = (char *) new char[256];
- this->subtitles.nbSubtitles = 0;
- this->inputFile->GetLine(this->inputBuffer);
- if(this->ParseSubtitle() == MP_RESULT_OK) {
- this->firstSubtitleFrame = this->firstFrame;
- this->previousLastFrame = 0;
- return MP_RESULT_OK;
- }
- }
- }
- return MP_RESULT_ERROR;
- }
- subtitles_t *MediaSubtitlerMicroDVD::GetSubtitles(DWORD frameNumber)
- {
- if(frameNumber < this->firstSubtitleFrame) {
- return NULL;
- }
- if(frameNumber < this->firstFrame && frameNumber > this->previousLastFrame) {
- return NULL;
- }
- if(frameNumber >= this->firstFrame && frameNumber < this->lastFrame) {
- return &this->subtitles;
- }
- else {
- this->SeekToFrame(frameNumber);
- return NULL;
- }
- return NULL;
- }
- MP_RESULT MediaSubtitlerMicroDVD::Close()
- {
- if(this->inputFile) {
- this->inputFile->Close();
- }
- return MP_RESULT_ERROR;
- }