Esempio n. 1
0
        /**
        // \fn public bool CreateTranscoder(string name, StreamType st, int sampleRate, int bitrate, string url, IPAddress ip, int port, int adminport, string password, int webradioId)
        //
        // \brief Creates a transcoder.
        //
        // \author Simon Menetrey
        // \date 26.05.2014
        //
        // \param name       The name.
        // \param st         The st.
        // \param sampleRate The sample rate.
        // \param bitrate    The bitrate.
        // \param url        URL of the document.
        // \param ip         The IP.
        // \param port       The port.
        // \param adminport  The administration port.
        // \param password   The password.
        // \param webradioId Identifier for the webradio.
        //
        // \return true if it succeeds, false if it fails.
        **/
        public bool CreateTranscoder(string name, StreamType st, int sampleRate, int bitrate, string url, IPAddress ip, int port, int adminport, string password, int webradioId)
        {
            string filename = DEFAULT_WEBRADIOS_FOLDER + this.Webradios[webradioId].Name + "/" + DEFAULT_TRANSCODERS_FOLDER;
            WebradioTranscoder transcoder;
            if (st == StreamType.AACPlus)
                transcoder = new TranscoderAacPlus(name,
                bitrate,
                sampleRate,
                ip,
                port,
                adminport,
                url,
                password,
                filename,
                filename);
            else
                transcoder = new TranscoderMp3(name,
                 bitrate,
                 sampleRate,
                 ip,
                 port,
                 adminport,
                 url,
                 password,
                 filename,
                 filename);

            transcoder.CalendarFile = DEFAULT_WEBRADIOS_FOLDER + this.Webradios[webradioId].Name + "/" + DEFAULT_CALENDAR_FILENAME;
            int id = this.Bdd.AddTranscoder(transcoder, webradioId);
            if (id == Bdd.ERROR)
                return false;
            transcoder.Id = id;
            transcoder.ConfigFilename = filename + id.ToString() + ".config";
            transcoder.LogFilename = filename + id.ToString() + ".log";
            this.Webradios[webradioId].Transcoders.Add(transcoder);
            transcoder.GenerateConfigFile(this.Webradios[webradioId].Playlists);
            this.Webradios[webradioId].GenerateConfigFiles();
            this.UpdateObservers();
            return true;
        }
Esempio n. 2
0
        /**
        // \fn public Dictionary<int,Webradio> LoadWebradios()
        //
        // \brief Loads the webradios from db. All webradio's elements are loaded too.
        //
        // \author Simon Menetrey
        // \date 26.05.2014
        //
        // \return The webradios list.
        **/
        public Dictionary<int, Webradio> LoadWebradios()
        {
            Dictionary<int, Webradio> webradios = new Dictionary<int, Webradio>();
            SQLiteDataReader reader = this.Controls.ExecuteDataReader("SELECT * FROM twebradio");
            while(reader.Read())
            {
                webradios.Add( int.Parse(reader["id"].ToString()), new Webradio(reader["name"].ToString(), int.Parse(reader["id"].ToString())));
            }
            reader.Close();

            foreach(KeyValuePair<int,Webradio> pair in webradios)
            {
                Webradio wr = pair.Value;
                //Server
                int id = wr.Id;
                reader = this.Controls.ExecuteDataReader("SELECT * FROM tserver WHERE webradioid = " + id.ToString());
                reader.Read();
                wr.Server = new WebradioServer(int.Parse(reader["port"].ToString()),
                    reader["logfilename"].ToString(),
                    reader["configfilename"].ToString(),
                    reader["password"].ToString(),
                    reader["adminpassword"].ToString(),
                    int.Parse(reader["maxlistener"].ToString()));
                reader.Close();
                //----

                //Calendar
                reader = this.Controls.ExecuteDataReader("SELECT id, filename FROM tcalendar WHERE webradioid = " + id.ToString());
                reader.Read();
                wr.Calendar = new WebradioCalendar(int.Parse(reader["id"].ToString()), reader["filename"].ToString());
                reader.Close();
                reader = this.Controls.ExecuteDataReader("SELECT ce.id AS EventId, ce.playlistid, ce.starttime, ce.duration, ce.name AS EventName, ce.repeat, ce.priority, ce.shuffle, ce.loopatend, p.name  AS PlaylistName, p.filename AS PlaylistFilename, at.name AS AudiotypeName FROM tcalendarevent ce, tplaylist p, taudiotype at WHERE ce.calendarid = " + wr.Calendar.Id + " AND ce.playlistid = p.id AND p.typeid = at.id");
                while(reader.Read())
                {
                    string[] time = reader["starttime"].ToString().Split(':');
                    TimeSpan start = new TimeSpan(int.Parse(time[0]),int.Parse(time[1]),int.Parse(time[2]));
                    time = reader["duration"].ToString().Split(':');
                    TimeSpan duration = new TimeSpan(int.Parse(time[0]),int.Parse(time[1]),int.Parse(time[2]));
                    Playlist playlist;
                    if (reader["AudiotypeName"].ToString() == AudioType.Music.ToString())
                        playlist = new PlaylistMusic(reader["PlaylistName"].ToString(), reader["PlaylistFilename"].ToString());
                    else
                        playlist = new PlaylistAd(reader["PlaylistName"].ToString(), reader["PlaylistFilename"].ToString());
                    wr.Calendar.Events.Add(new CalendarEvent(int.Parse(reader["EventId"].ToString()), reader["EventName"].ToString(),
                        start,
                        duration,
                        int.Parse(reader["repeat"].ToString()),
                        int.Parse(reader["priority"].ToString()),
                        Convert.ToBoolean(reader["shuffle"].ToString()),
                        Convert.ToBoolean(reader["loopatend"].ToString()),
                        playlist));
                }
                reader.Close();
                //---

                //Playlists
                reader = this.Controls.ExecuteDataReader("SELECT p.id, p.name AS PlaylistName, p.filename, t.name AS AudioType FROM tplaylist p, taudiotype t WHERE p.typeid = t.id AND webradioid = " + id.ToString());
                while(reader.Read())
                {
                    Playlist p = null;
                    if(reader["AudioType"].ToString() == AudioType.Ad.ToString())
                        p = new PlaylistAd(int.Parse(reader["id"].ToString()), reader["PlaylistName"].ToString(), reader["filename"].ToString());
                    else if(reader["AudioType"].ToString() == AudioType.Music.ToString())
                        p = new PlaylistMusic(int.Parse(reader["id"].ToString()), reader["PlaylistName"].ToString(), reader["filename"].ToString());
                    wr.Playlists.Add(p);
                }
                reader.Close();
                foreach(Playlist playlist in wr.Playlists)
                {
                    reader = this.Controls.ExecuteDataReader("SELECT m.filename FROM tmusic m, tplaylist_has_music pm WHERE pm.playlistid = " + playlist.Id + " AND m.id = pm.musicid");
                    while(reader.Read())
                    {
                        playlist.AudioFileList.Add(reader["filename"].ToString());
                    }
                }
                reader.Close();
                //Transcoders
                reader = this.Controls.ExecuteDataReader("SELECT c.filename AS CalendarFilename, tr.id, tr.name AS TransName, tr.bitrate, tr.samplerate, tr.url, tr.ip, tr.port, tr.adminport, tr.password, tr.configfilename, tr.logfilename, st.name AS StreamName FROM tcalendar c, ttranscoder tr, tstreamtype st WHERE tr.webradioid = " + id.ToString() + " AND tr.streamtypeid = st.id AND c.webradioid = " + id.ToString());
                while(reader.Read())
                {
                    WebradioTranscoder trans = null;
                    if(reader["StreamName"].ToString() == StreamType.MP3.ToString())
                        trans = new TranscoderMp3(int.Parse(reader["id"].ToString()),
                            reader["TransName"].ToString(),
                            int.Parse(reader["bitrate"].ToString()),
                            int.Parse(reader["samplerate"].ToString()),
                            IPAddress.Parse(reader["ip"].ToString()),
                            int.Parse(reader["port"].ToString()),
                            int.Parse(reader["adminport"].ToString()),
                            reader["url"].ToString(),
                            reader["password"].ToString(),
                            reader["configfilename"].ToString(),
                            reader["logfilename"].ToString());
                    else
                        trans = new TranscoderAacPlus(int.Parse(reader["id"].ToString()),
                            reader["TransName"].ToString(),
                            int.Parse(reader["bitrate"].ToString()),
                            int.Parse(reader["samplerate"].ToString()),
                            IPAddress.Parse(reader["ip"].ToString()),
                            int.Parse(reader["port"].ToString()),
                            int.Parse(reader["adminport"].ToString()),
                            reader["url"].ToString(),
                            reader["password"].ToString(),
                            reader["configfilename"].ToString(),
                            reader["logfilename"].ToString());
                    trans.CalendarFile = reader["CalendarFilename"].ToString();
                    wr.Transcoders.Add(trans);
                }
                reader.Close();
                //---

            }

            return webradios;
        }