?? channel.cpp
字號(hào):
/* * 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 "main.h"#define USES_BASECLASS#include "video.h"#include "wxgui/Channel_List.h"#include <time.h>//#define DEBUG#include "log.h"#define MODULE "Channel"int Channel::Open(CStr& file){ char line[80]; FILE *list; if(file.empty()) return 0; list = fopen(file.c_str(), "r"); if(!list) { ERROR_MSG("Cannot open file %s", file.c_str()); return 0; } // First line shoule be #EXTM3U // EXTM3U should be optional/* if(!fgets(line, 80, list)) { ERROR_MSG("Emtpy file %s", file); return 0; } if(strcmp(line, "#EXTM3U")) { ERROR_MSG("Not an extended m3u playlist"); return 0; }*/ // Read until EOF int i = 0, j; while(fgets(line, 80, list)) { i++; j = strlen(line) - 1; // Delete all control characters at the end while((j >= 0) && iscntrl(line[j])) { line[j] = '\0'; j--; } if((strlen(line) < 1) || (!strcmp(line, "#EXTM3U"))) { DEBUG_MSG("Skipping empty line %d", i); continue; } channels[num].type = 0; // Extended info char *c; if(!strncmp(line, "#EXTINF", 7)) { c = strrchr(line, ','); if(c) { c++; channels[num].name = c; DEBUG_MSG("Found Channel name %s", c); } // Next line should be channel info if(!fgets(line, 80, list)) { ERROR_MSG("Truncated file at line %d", i); fclose(list); return 0; } j = strlen(line) - 1; while((j >= 0) && iscntrl(line[j])) { line[j] = '\0'; j--; } if((c = strchr(c, ';'))) { *c = '\0'; } if((strlen(line) > 6) && !strncmp(line, "udp://", 6)) { channels[num].type = 1; c = line + 6; if(*c == '@') c++; } else { c = line; } } else { c = line; } channels[num].location = c; DEBUG_MSG("Found Channel location %s", c); num++; if(num == MAX_CHANNELS) { ERROR_MSG("Max number for channel list is %d", MAX_CHANNELS); break; } } ERROR_MSG("Found %d channels", num); fclose(list); return num;}bool Channel::Close(){ // Check for recording in progress if((current) && (sdl.recording)) {#if (C_HAVE_WXGUI) if(wxMessageBox(wxT("Recording is in progress and changing the channel will stop it.\nDo you want to continue?"), wxT("Recording in progress"), wxICON_QUESTION | wxYES_NO) == wxNO) return false;#endif sdl.recording = false; } sdl_bar.SetRec(sdl.recording); if(source) { SAFE_DELETE(source); SDL_PauseAudio(1); close_audio(); SDL_Event event; // Wait for quit events (also process any pending events) while((sdl.count) || (events->Peek())) { events->Wait(&event); sdl.decoder = (Decoder *)event.user.data1; // Decoders might be late, sending the event when we are already // closing the channel, they should quit sooner or later :-) if(sdl.decoder) sdl.count++; else sdl.count--; LOG_MSG("Received decoder address event: 0x%p, remaining: %d", sdl.decoder, sdl.count); } ERROR_MSG("Channel closed."); } if(current) { last = current; current = 0; } source = NULL; return true;}bool Channel::SetChannel(unsigned int n){ // 0 is an invalid channel if((n == 0) || (n > num)) return false; if(!Close()) return false; // because we decrement n by 1 :-) n--; // Just for the fun of it SDL_Delay(50); if(sdl.recording == false) sdl.filename.clear(); try { switch (channels[n].type) { case 0: source = new fileSource; break; case 1: source = new udpSource(sdl.iface, sdl.filename); break; default: ERROR_MSG("Invalid channel type"); break; } } catch(const char *c) { fprintf(stderr, "[%d] EXCEPTION: %s\n", SDL_GetTicks(), c); return false; } current = n + 1; sdl_bar.SetChannel(current, channels[n].name); ERROR_MSG("Set channel to %d:%s", current, channels[n].name.c_str()); bool result = source->Open(channels[n].location);#if (C_HAVE_WXGUI) if((result) && (gui.wxChannelList != NULL) && (gui.wxChannelList->IsVisible())) { gui.wxChannelList->FocusChanel(sdl.channel->GetNum()); }#endif return result;}bool Channel::OpenFile(CStr& filename){ if(filename.empty()) return false; if(!Close()) return false; SDL_Delay(50); try { source = new fileSource; } catch(const char *c) { fprintf(stderr, "[%d] EXCEPTION: %s\n", SDL_GetTicks(), c); return false; } sdl_bar.SetChannel(0, filename); ERROR_MSG("Open file: %s", filename.c_str()); return source->Open(filename);}void Channel::ToggleRecord(){ if(source) { source->TerminateThread(); if(sdl.recording) { source->configure(NULL); sdl.recording = false; } else { struct tm *now; time_t t; time(&t); now = localtime(&t); if((*sdl.recordingDir.last() != '\\') && (*sdl.recordingDir.last() != '/')) { sdl.recordingDir += '/'; } sdl.filename.Format("%s%d%02d%02d %02d%02d%02d - %d %s.ts", sdl.recordingDir.c_str(), now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec, GetNum(), GetName().c_str()); source->configure(sdl.filename.c_str()); sdl.recording = true; } source->ThreadCreate(); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -