コード例 #1
0
        public void EndPage()
        {
            if (_pageNumInProgress == -1)
            {
                return;                     // no page in progress
            }
            if ((_pageNumInProgress < 0 || _pageNumInProgress >= 966))
            {
                ServiceRegistration.Get <ILogger>().Debug("DANGER DANGER!, endpage with pageNumInProgress = %i",
                                                          _pageNumInProgress);
                return;
            }

            ServiceRegistration.Get <ILogger>().Debug("Finished Page {0}", _pageNumInProgress);
            //bool hasContent = false;

            for (int i = 0; i < 25; i++)
            {
                bool   boxed       = false;
                byte[] lineContent = GetLine(i);

                for (int j = 0; j < 40; j++)
                {
                    // Remove spacing attributes ( see 12.2 of the draft)
                    // FIXME: Some subtitles will have the attributed 'double height'
                    // and therefore have an empty line between subs.

                    // �s this content a space attribute?
                    if (MSB3_NP(lineContent[j]) == 0)
                    {
                        if (LSB4(lineContent[j]) == SPACE_ATTRIB_BOX_START)
                        {
                            //LogDebug("BS - boxed is true");
                            boxed = true;
                            //hasContent = true;
                        }
                        else if (LSB4(lineContent[j]) == SPACE_ATTRIB_BOX_END)
                        {
                            //LogDebug("BE - boxed is false");
                            boxed = false;
                        }
                        // remove spacing attribute
                        lineContent[j] = TELETEXT_BLANK;
                    }
                    else if (!boxed)
                    {
                        // if we are not in boxed mode,
                        // we dont want to keep the content
                        lineContent[j] = TELETEXT_BLANK;
                        Assert(true, "EndPage: Boxed not set as expected");
                    }
                }
                SetLine(i, lineContent);
            }


            /*if(!hasContent) {
             * ServiceRegistration.Get<ILogger>().Debug("(BLANK PAGE)");
             * }*/

            byte[] text = new byte[TELETEXT_WIDTH * TELETEXT_LINES];
            Array.Copy(_pageContent, text, TELETEXT_LINES * TELETEXT_WIDTH);
            TextConversion.Convert(_language, text);

            LineContent[] lc = new LineContent[TELETEXT_LINES];

            string realLang = "";

            lock (LangInfo)
            {
                if (LangInfo.ContainsKey(_pageNumInProgress))
                {
                    realLang = LangInfo[_pageNumInProgress];
                }
            }

            for (int line = 0; line < TELETEXT_LINES; line++)
            {
                StringBuilder lineBuilder = new StringBuilder();
                for (int c = 0; c < TELETEXT_WIDTH; c++)
                {
                    lineBuilder.Append((char)text[line * TELETEXT_WIDTH + c]);
                }
                lc[line] = new LineContent();
                if (realLang != "")
                {
                    lc[line].line = TextConversion.ConvertLineLangSpecific(realLang, lineBuilder.ToString());
                }
                else
                {
                    lc[line].line = lineBuilder.ToString();
                }
                lc[line].doubleHeight = true;
            }

            StringBuilder textBuilder = new StringBuilder();

            for (int i = 0; i < text.Length; i++)
            {
                //sbuf.Append((char)text[i]);
                textBuilder.Append((char)text[i]);

                //sbuf.Append("" + ((int)pageContent[i]) + " ");
                if (((i + 1) % 40) == 0)
                {
                    textBuilder.Append('\n');
                }
            }

            // prepare subtitle
            TextSubtitle sub = new TextSubtitle();

            sub.Encoding = _language;
            sub.Page     = _pageNumInProgress;

            sub.Language = realLang;

            sub.Text         = textBuilder.ToString();
            sub.LineContents = lc;
            sub.TimeOut      = ulong.MaxValue; // never timeout (will be replaced by other page)
            sub.TimeStamp    = _presentTime;
            Assert(String.IsNullOrEmpty(sub.Text), "Sub.text == null!");

            if (_owner.SubPageInfoCallback != null)
            {
                TeletextPageEntry pageEntry = new TeletextPageEntry
                {
                    Language = String.Copy(sub.Language),
                    Encoding = (TeletextCharTable)sub.Encoding,
                    Page     = sub.Page
                };

                _owner.SubPageInfoCallback(pageEntry);
            }

            _owner.SubtitleRender.OnTextSubtitle(ref sub);
            _pageNumInProgress = -1;
        }
コード例 #2
0
    // Currently unused, teletext subtitles are not yet (re-)implemented!
    public void OnTextSubtitle(ref TextSubtitle sub)
    {
      ServiceRegistration.Get<ILogger>().Debug("On TextSubtitle called");
      try
      {
        if (sub.Page == _activeSubPage)
        {
          ServiceRegistration.Get<ILogger>().Debug("Page: " + sub.Page);
          ServiceRegistration.Get<ILogger>().Debug("Character table: " + sub.Encoding);
          ServiceRegistration.Get<ILogger>().Debug("Timeout: " + sub.TimeOut);
          ServiceRegistration.Get<ILogger>().Debug("Timestamp" + sub.TimeStamp);
          ServiceRegistration.Get<ILogger>().Debug("Language: " + sub.Language);

          String content = sub.Text;
          if (content == null)
          {
            ServiceRegistration.Get<ILogger>().Error("OnTextSubtitle: sub.txt == null!");
            return;
          }
        }
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Error("Problem with TEXT_SUBTITLE");
        ServiceRegistration.Get<ILogger>().Error(e);
      }

      try
      {
        // if we dont need the subtitle
        if (!_renderSubtitles || _useBitmap || (_activeSubPage != sub.Page))
        {
          ServiceRegistration.Get<ILogger>().Debug("Text subtitle (page {0}) discarded: useBitmap is {1} and activeSubPage is {2}", sub.Page, _useBitmap, _activeSubPage);
          return;
        }
        ServiceRegistration.Get<ILogger>().Debug("Text subtitle (page {0}) ACCEPTED: useBitmap is {1} and activeSubPage is {2}", sub.Page, _useBitmap, _activeSubPage);

        Subtitle subtitle = new Subtitle
                              {
                                SubBitmap = RenderText(sub.LineContents),
                                TimeOut = sub.TimeOut,
                                PresentTime = sub.TimeStamp / 90000.0f + _startPos,
                                Height = (uint) SkinContext.SkinResources.SkinHeight,
                                Width = (uint) SkinContext.SkinResources.SkinWidth,
                                FirstScanLine = 0
                              };

        lock (_subtitles)
        {
          while (_subtitles.Count >= MAX_SUBTITLES_IN_QUEUE)
          {
            ServiceRegistration.Get<ILogger>().Debug("SubtitleRenderer: Subtitle queue too big, discarding first element");
            _subtitles.RemoveFirst();
          }
          _subtitles.AddLast(subtitle);

          ServiceRegistration.Get<ILogger>().Debug("SubtitleRenderer: Text subtitle added, now have {0} subtitles in cache {1} pos on last render was {2}", _subtitles.Count, subtitle, _currentTime);
        }
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Error("Problem processing text subtitle");
        ServiceRegistration.Get<ILogger>().Error(e);
      }
    }
コード例 #3
0
        // Currently unused, teletext subtitles are not yet (re-)implemented!
        public void OnTextSubtitle(ref TextSubtitle sub)
        {
            ServiceRegistration.Get <ILogger>().Debug("On TextSubtitle called");
            try
            {
                if (sub.Page == _activeSubPage)
                {
                    ServiceRegistration.Get <ILogger>().Debug("Page: " + sub.Page);
                    ServiceRegistration.Get <ILogger>().Debug("Character table: " + sub.Encoding);
                    ServiceRegistration.Get <ILogger>().Debug("Timeout: " + sub.TimeOut);
                    ServiceRegistration.Get <ILogger>().Debug("Timestamp" + sub.TimeStamp);
                    ServiceRegistration.Get <ILogger>().Debug("Language: " + sub.Language);

                    String content = sub.Text;
                    if (content == null)
                    {
                        ServiceRegistration.Get <ILogger>().Error("OnTextSubtitle: sub.txt == null!");
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Problem with TEXT_SUBTITLE");
                ServiceRegistration.Get <ILogger>().Error(e);
            }

            try
            {
                // if we dont need the subtitle
                if (!_renderSubtitles || _useBitmap || (_activeSubPage != sub.Page))
                {
                    ServiceRegistration.Get <ILogger>().Debug("Text subtitle (page {0}) discarded: useBitmap is {1} and activeSubPage is {2}", sub.Page, _useBitmap, _activeSubPage);
                    return;
                }
                ServiceRegistration.Get <ILogger>().Debug("Text subtitle (page {0}) ACCEPTED: useBitmap is {1} and activeSubPage is {2}", sub.Page, _useBitmap, _activeSubPage);

                Subtitle subtitle = new Subtitle
                {
                    SubBitmap     = RenderText(sub.LineContents),
                    TimeOut       = sub.TimeOut,
                    PresentTime   = sub.TimeStamp / 90000.0f + _startPos,
                    Height        = (uint)SkinContext.SkinResources.SkinHeight,
                    Width         = (uint)SkinContext.SkinResources.SkinWidth,
                    FirstScanLine = 0
                };

                lock (_subtitles)
                {
                    while (_subtitles.Count >= MAX_SUBTITLES_IN_QUEUE)
                    {
                        ServiceRegistration.Get <ILogger>().Debug("SubtitleRenderer: Subtitle queue too big, discarding first element");
                        _subtitles.RemoveFirst();
                    }
                    _subtitles.AddLast(subtitle);

                    ServiceRegistration.Get <ILogger>().Debug("SubtitleRenderer: Text subtitle added, now have {0} subtitles in cache {1} pos on last render was {2}", _subtitles.Count, subtitle, _currentTime);
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Problem processing text subtitle");
                ServiceRegistration.Get <ILogger>().Error(e);
            }
        }
コード例 #4
0
    public void EndPage()
    {
      if (_pageNumInProgress == -1) return; // no page in progress
      if ((_pageNumInProgress < 0 || _pageNumInProgress >= 966))
      {
        ServiceRegistration.Get<ILogger>().Debug("DANGER DANGER!, endpage with pageNumInProgress = %i",
                                                 _pageNumInProgress);
        return;
      }

      ServiceRegistration.Get<ILogger>().Debug("Finished Page {0}", _pageNumInProgress);
      //bool hasContent = false;

      for (int i = 0; i < 25; i++)
      {
        bool boxed = false;
        byte[] lineContent = GetLine(i);

        for (int j = 0; j < 40; j++)
        {
          // Remove spacing attributes ( see 12.2 of the draft)
          // FIXME: Some subtitles will have the attributed 'double height'
          // and therefore have an empty line between subs.

          // �s this content a space attribute?
          if (MSB3_NP(lineContent[j]) == 0)
          {
            if (LSB4(lineContent[j]) == SPACE_ATTRIB_BOX_START)
            {
              //LogDebug("BS - boxed is true");
              boxed = true;
              //hasContent = true;
            }
            else if (LSB4(lineContent[j]) == SPACE_ATTRIB_BOX_END)
            {
              //LogDebug("BE - boxed is false");
              boxed = false;
            }
            // remove spacing attribute
            lineContent[j] = TELETEXT_BLANK;
          }
          else if (!boxed)
          {
            // if we are not in boxed mode,
            // we dont want to keep the content
            lineContent[j] = TELETEXT_BLANK;
            Assert(true, "EndPage: Boxed not set as expected");
          }
        }
        SetLine(i, lineContent);
      }


      /*if(!hasContent) {
        ServiceRegistration.Get<ILogger>().Debug("(BLANK PAGE)");
      }*/

      byte[] text = new byte[TELETEXT_WIDTH*TELETEXT_LINES];
      Array.Copy(_pageContent, text, TELETEXT_LINES*TELETEXT_WIDTH);
      TextConversion.Convert(_language, text);

      LineContent[] lc = new LineContent[TELETEXT_LINES];

      string realLang = "";

      lock (LangInfo)
      {
        if (LangInfo.ContainsKey(_pageNumInProgress))
        {
          realLang = LangInfo[_pageNumInProgress];
        }
      }

      for (int line = 0; line < TELETEXT_LINES; line++)
      {
        StringBuilder lineBuilder = new StringBuilder();
        for (int c = 0; c < TELETEXT_WIDTH; c++)
        {
          lineBuilder.Append((char) text[line*TELETEXT_WIDTH + c]);
        }
        lc[line] = new LineContent();
        if (realLang != "")
        {
          lc[line].line = TextConversion.ConvertLineLangSpecific(realLang, lineBuilder.ToString());
        }
        else
        {
          lc[line].line = lineBuilder.ToString();
        }
        lc[line].doubleHeight = true;
      }

      StringBuilder textBuilder = new StringBuilder();
      for (int i = 0; i < text.Length; i++)
      {
        //sbuf.Append((char)text[i]);
        textBuilder.Append((char) text[i]);

        //sbuf.Append("" + ((int)pageContent[i]) + " ");
        if (((i + 1)%40) == 0)
        {
          textBuilder.Append('\n');
        }
      }

      // prepare subtitle
      TextSubtitle sub = new TextSubtitle();
      sub.Encoding = _language;
      sub.Page = _pageNumInProgress;

      sub.Language = realLang;

      sub.Text = textBuilder.ToString();
      sub.LineContents = lc;
      sub.TimeOut = ulong.MaxValue; // never timeout (will be replaced by other page)
      sub.TimeStamp = _presentTime;
      Assert(String.IsNullOrEmpty(sub.Text), "Sub.text == null!");

      if (_owner.SubPageInfoCallback != null)
      {
        TeletextPageEntry pageEntry = new TeletextPageEntry
                                        {
                                          Language = String.Copy(sub.Language),
                                          Encoding = (TeletextCharTable) sub.Encoding,
                                          Page = sub.Page
                                        };

        _owner.SubPageInfoCallback(pageEntry);
      }

      _owner.SubtitleRender.OnTextSubtitle(ref sub);
      _pageNumInProgress = -1;
    }