📄 file.cpp
字号:
/* * Copyright (C) 2005-2007 gulikoza * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* $Id$ */#include "iptv.h"#define USES_BASECLASS#include "video.h"//#define DEBUG#include "log.h"#define MODULE "fileSource"bool fileSource::Open(CStr& s){ file = fopen(s.c_str(), "rb"); if(!file) { ERROR_MSG("Error opening %s", s.c_str()); return false; } DEBUG_MSG("Opened %s", s.c_str()); fseek(file, 0, SEEK_SET); // Start worker thread ThreadCreate(); return true;}#define FILECHUNK 1316int fileSource::Run(){ // Connect the splitter Splitter * splitter; try { splitter = new mpeg_demux(true); } catch (const char * c) { fprintf(stderr, "[%d] EXCEPTION: %s\n", SDL_GetTicks(), c); TerminateThread(false); return 0; } // File source uses system clock timer->unlocked = true; if(!splitter) { ERROR_MSG("Error connecting splitter, teminating thread!"); return -1; } // Copy FILE structure to local variable FILE * fd = file; unsigned char buffer[FILECHUNK]; int n = 0; ERROR_MSG("(ThreadID: %u) init complete", SDL_ThreadID()); while(ThreadRun()) { n += fread(buffer+n, sizeof(char), FILECHUNK-n, fd); DEBUG_MSG("%d bytes are available", n); // ProcessData will block when decoding buffer is full n = splitter->ProcessData(buffer, n); // Copy unused data to the begining of the buffer if(n > 0) SDL_memcpy(buffer, buffer+(FILECHUNK-n), n); if(feof(fd) || ferror(fd)) { LOG_MSG("Error or of file"); break; } } SAFE_DELETE(splitter); ERROR_MSG("(ThreadID: %u) finish complete", SDL_ThreadID()); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -