Ir para o conteúdo

 Voltar a Ginga-J: Imp...
Tela cheia

Redimensionr vídeo usando Ginga-J

18 de Abril de 2011, 10:54 , por Desconhecido - | Ninguém seguindo este artigo por enquanto.
Visualizado 22 vezes

Olá,

 Estou querendo fazer uma aplicação que ocupe a tela em 'L', e para isso redimensione o vídeo para um canto da tela.

Existe algo pronto na implementação de referência para essa função?

Caso não esteja implementado, penso que isso lida com o GingaCC, certo? Meu C++ deve estar enferrujado...

Autor: Arthur Gusmão


22 comentários

  • 49b94670a089dfa9aea15ed3e81e513c?only path=false&size=50&d=404Bruno Lima(usuário não autenticado)
    18 de Abril de 2011, 11:29

     

    Precisa ser em Java ? Em NCL eh trivial uma aplicacao assim.

  • B31d812c95fedf9d4d7a0eb1de39c636?only path=false&size=50&d=404Marcos Vinícius Henke Arnoldo(usuário não autenticado)
    19 de Abril de 2011, 1:59

     

    "No meu tempo" era assim... (no tempo do GEM, lá por 2007)

     Nesta primeira classe (B4Player) tenho 3 métodos de exemplo, cada um usando uma biblioteca diferente:

    resizeVideoAWT, resizeVideoHAVi e resizeVideoDVB

    Segue a classe completa:

    import java.awt.Rectangle;
    import javax.media.GainControl;
    import javax.media.Player;
    import javax.tv.media.*;
    import org.davic.media.*;
    import org.dvb.media.*;
    import javax.tv.service.selection.*;
    import org.havi.ui.*;

    /**
     *  Disponibiliza mÈtodos para manipulaÁ„o do Player de vÌdeo.
     *  @author Marcos Henke
     *  nov-2007
     */
    public class B4Player
    {
      private static Player thePlayer;

      /**
       * Retorna a inst‚ncia do objeto Player de vÌdeo.
       * @return Objeto Player.
       */
      public static Player getPlayer()
      {
        if (thePlayer == null)
        {
          // Se ainda n„o foi atribuÌdo o player, atribui
          try
          {
            // Busca o contexto do serviÁo
            ServiceContextFactory oServiceContextFactory = ServiceContextFactory.getInstance();
            ServiceContext oServiceContext = oServiceContextFactory.getServiceContext(TheXlet.getInstance().getContext());
            if (oServiceContext != null)
            {
              // Se encontrou, busca os manipuladores de conte˙do
              ServiceContentHandler[] oServiceContentHandler = oServiceContext.getServiceContentHandlers();
              // Procura por um player de vÌdeo
              for (int i=0; i<oServiceContentHandler.length; i++)
                if (oServiceContentHandler[i] instanceof Player)
                {
                  // Se encontrou, retorna a inst‚ncia
                  thePlayer = (Player)oServiceContentHandler[i];
                  break;
                }
            }
          }
          catch (SecurityException e)
          {
            e.printStackTrace();
          }
          catch (ServiceContextException e)
          {
            e.printStackTrace();
          }     
        }

        return thePlayer;     
      }
     
      /**
       * Ativa ou desativa a exibiÁ„o de legendas (ClosedCaption).
       * Origem: MHP Wiki - mhpk​dbwi​ki.s​3.un​i-du​e.de​/mhp​kdbw​iki/​inde​x.ph​p/Pr​esen​tati​on_c​ontr​ol
       * @param PbVisible Se true, exibe Closed Captions. Se false, oculta.
       */
      public static void setSubtitling(boolean PbVisible)
      {
        Player oPlayer = B4Player.getPlayer(); // Pega o player
        if (oPlayer != null)
        {
          // Busca o controle de legendas
          SubtitlingLanguageControl oSubtitlingLanguageControl = (SubtitlingLanguageControl)oPlayer.getControl("org.davic.media.SubtitlingLanguageControl");
          if (oSubtitlingLanguageControl != null)
          {
            // Busca as legendas disponÌveis
            System.out.println("SubtitlingLanguageControl encontrado");
            String[] aLanguages = oSubtitlingLanguageControl.listAvailableLanguages();
            if (aLanguages.length > 0)
            {
              // Se encontrou alguma legenda disponÌvel
              System.out.println("Legendas disponÌveis");
              oSubtitlingLanguageControl.setSubtitling(PbVisible); // Ativa ou desativa conforme o par‚metro
            }
            else
              System.out.println("Legendas n„o disponÌveis");
          }
          else
            System.out.println("SubtitlingLanguageControl nao encontrado");
        }
      }
     
      /**
       * Aplica o tamanho definido ao vÌdeo.
       * Utiliza biblioteca AWT.
       * @param PoAwtVideoSize Objeto AWTVideoSize contendo o tamanho desejado.
       * @return True se aplicou o tamanho.
       */
      public static boolean resizeVideoAWT(AWTVideoSize PoAwtVideoSize)
      {
        Player oPlayer = B4Player.getPlayer(); // Pega o player
        if (oPlayer != null)
        {
          AWTVideoSizeControl oAwtVideoSizeControl = (AWTVideoSizeControl)oPlayer.getControl("javax.tv.media.AWTVideoSizeControl");
          if (oAwtVideoSizeControl.setSize(PoAwtVideoSize))
          {
            System.out.println("Video redimensionado usando AWT: " + PoAwtVideoSize);
            return true;
          }
        }
        return false;
      }
     
      /**
       * Aplica o tamanho definido ao vÌdeo.
       * Utiliza biblioteca HAVi.
       * Origem: Exemplos postados no Forum JavaTV - foru​m.ja​va.s​un.c​om/f​orum​.jsp​a?fo​rumI​D=36
       * @param PoRectangle Tamanho desejado.
       * @return True se aplicou o tamanho.
       */
      public static boolean resizeVideoHAVi(HScreenRectangle PoRectangle)
      {
        HScreen oScreen = HScreen.getDefaultHScreen();
        HVideoDevice oDevice = oScreen.getDefaultHVideoDevice();
        boolean bReserved = oDevice.reserveDevice(TheXlet.getInstance()); // Reserva a camada de vÌdeo para efetuar alteraÁ„o
       
        HVideoConfigTemplate oTemplate = new HVideoConfigTemplate();
        oTemplate.setPreference(HScreenConfigTemplate.SCREEN_RECTANGLE, PoRectangle, HScreenConfigTemplate.PREFERRED);
       
        // Procura uma configuraÁ„o mais parecida com a definida no template
        HVideoConfiguration oConfiguration = oDevice.getBestConfiguration(oTemplate);
        if (oConfiguration != null)
        {
          try
          {
            // Se encontrou, atribui a configuraÁ„o
            if (oDevice.setVideoConfiguration(oConfiguration))
            {
              System.out.println("Video redimensionado usando HAVi: " + PoRectangle);
              return true;
            }
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }
        System.out.println("Nao foi possivel redimensionar com HAVi");
        return false;
      }   
     
      /**
       * Aplica o tamanho definido ao vÌdeo.
       * Utiliza biblioteca DVB.
       * OBS.: Conforme conversa com Steve Morris, o XletView e alguns outros emuladores
       * n„o suportam BackgroundVideoPresentationControl, assim como alguns set-top-boxes.
       * Origem: www.​inte​ract​ivet​vweb​.org - JMFExample.java
       * @param PoClipRegion Regi„o que ser· efetuado o crop/clip.
       * @param PfWidth Escala a ampliar a largura do vÌdeo. Ex.: 1.5
       * @param PfHeight Escala a ampliar a altura do vÌdeo. Ex.: 1.5
       * @return True se aplicou o tamanho.
       */ 
      public static boolean resizeVideoDVB(Rectangle PoClipRegion, float PfWidth, float PfHeight)
      {
        Player oPlayer = B4Player.getPlayer(); // Pega o player
        if (oPlayer != null)
        {   
          org.dvb.media.BackgroundVideoPresentationControl oBgVideoControl = (org.dvb.media.BackgroundVideoPresentationControl) oPlayer.getControl("org.dvb.media.BackgroundVideoPresentationControl");
          if (oBgVideoControl != null)
          {
            // Se o emulador/set-top-box suportar BackgroundVideoPresentationControl...
            VideoTransformation oTransformation = new VideoTransformation();
            oTransformation.setClipRegion(PoClipRegion);            // Define a ·rea interna do vÌdeo a cortar para redimensionar
            oTransformation.setScalingFactors(PfWidth, PfHeight);   // Define o novo tamanho. Deve ser no formato float, ex.: 1.5
            oTransformation.setVideoPosition(new HScreenPoint((float)0.0, (float)0.0)); // Define a posiÁ„o. Nesta abordagem, sempre 0,0

            oTransformation = oBgVideoControl.getClosestMatch(oTransformation); // Retorna um objeto com as configuraÁıes mais aproximadas
            if (oBgVideoControl.setVideoTransformation(oTransformation))
            {
              System.out.println("Video redimensionado usando DVB: " + PoClipRegion);
              return true;
            }
            else
              System.out.println("BackgroundVideoPresentationControl nao suportado");
          }
        }
        System.out.println("Nao foi possivel redimensionar com DVB");   
        return false;
      }
     
      /**
       * Ativa ou desativa o mudo.
       * @param PbMute Se true, ativa o mudo. False, desativa.
       * @return True se conseguiu aplicar a configuraÁ„o.
       */
      public static boolean setMute(boolean PbMute)
      {
        Player oPlayer = B4Player.getPlayer(); // Pega o player
        if (oPlayer != null)
        {   
          GainControl oGainControl = oPlayer.getGainControl(); // Controle de ganho de volume
          if (oGainControl != null)
          {
            oGainControl.setMute(PbMute);
            System.out.println("Mudo: " + PbMute);
            return true;
          }
          else
            System.out.println("GainControl nao suportado");         
        }
        return false;
      } 

      /**
       * Atribui o ganho de ·udio.
       * @param PiAudioLevel Volume de ganho desejado.
       * @return True se aplicou o volume.
       */
      public static boolean setAudioLevel(int PiAudioLevel)
      {
        Player oPlayer = B4Player.getPlayer(); // Pega o player
        if (oPlayer != null)
        {   
          GainControl oGainControl = oPlayer.getGainControl(); // Controle de ganho de ·udio
          if (oGainControl != null)
          {
            oGainControl.setLevel((float)PiAudioLevel);
            System.out.println("setAudioLevel: " + PiAudioLevel);
            return true;
          }
          else
            System.out.println("GainControl nao suportado");         
        }
        return false;
      }  
    }

     -------------------------------------

     

    Nesta segunda classe há exemplos de como utilizar os métodos de redimensionamento:

     

    import java.awt.Rectangle;
    import javax.media.Player;
    import javax.tv.media.*;
    import org.havi.ui.HScreenRectangle;

    /**
     *  Controla o redimensionamento do vÌdeo.
     *  @author Marcos Henke
     *  out-2007
     */
    public class Zoom
    {
      private TheXlet theXlet;
      /**
       * Tamanho original do vÌdeo.
       */
      public final AWTVideoSize oOriginalVideoSize;
      private int iCurrentZoomIndex;
      private Rectangle aAvailSizes[], aCropSizes[];
      private static Zoom theZoom;

      // ------------- Class and Interface Methods ---------------------------- 
     
      /**
       * Construtor.
       */
      public Zoom()
      {
        this.iCurrentZoomIndex = 0; // 100%
        this.theXlet = TheXlet.getInstance();
        this.oOriginalVideoSize = getVideoSize(); // Guarda o tamanho do vÌdeo original
        createZoomSizes();
      }
     
      // ------------- Getters and Setters ---------------------------- 

      /**
       * Retorna a inst‚ncia do Zoom.
       * @return Objeto Zoom.
       */
      public static Zoom getInstance()
      {
        if (theZoom == null)
          theZoom = new Zoom();
        return theZoom;
      }
     
      public int getCurrentZoomIndex()
      {
        return this.iCurrentZoomIndex;
      }
     
      /**
       * Retorna o tamanho atual do vÌdeo.
       */
      public AWTVideoSize getVideoSize()
      {
        Player oPlayer = B4Player.getPlayer();
        if (oPlayer != null)
        {
          AWTVideoSizeControl oAwtVideoSizeControl = (AWTVideoSizeControl)oPlayer.getControl("javax.tv.media.AWTVideoSizeControl");
          return oAwtVideoSizeControl.getSize();
        }
        return null;
      }
     
      public void setZoom(int PiZoomIndex)
      {
        System.out.println("setZoom: from " + iCurrentZoomIndex + " to " +  PiZoomIndex);     

        if ((PiZoomIndex >= 0) &&
            (PiZoomIndex <= 4) &&
            (PiZoomIndex != iCurrentZoomIndex))
        {
          if (!B4Player.resizeVideoDVB(aCropSizes[PiZoomIndex], (float)1.5, (float)1.5))  // Tenta com DVB, pois seria o ideal
            if (!B4Player.resizeVideoHAVi(new HScreenRectangle(0, 0, 1000, 800)))         // Tenta com HAVi
            {
              // Se n„o foi possÌvel, executa com AWT. Ese mÈtodo funciona mesmo no XletView
              Rectangle retA = aAvailSizes[iCurrentZoomIndex];  // PosiÁ„o e Tamanho anterior
              Rectangle retB = aAvailSizes[PiZoomIndex];        // PosiÁ„o e Tamanho atual       
              B4Player.resizeVideoAWT(new AWTVideoSize(retA, retB));
            }
         
          iCurrentZoomIndex = PiZoomIndex;
        }
      }
     
      // ------------- User Methods ---------------------------- 

      /**
       * Cria uma lista de tamanhos possÌveis
       */
      private void createZoomSizes()
      {
        // Para utilizr com AWT
        aAvailSizes = new Rectangle[4];
        aAvailSizes[0] = new Rectangle(0, 0, 800, 600);         // 100%  
        aAvailSizes[1] = new Rectangle(0, 0, 400, 300);         // 50%  
        aAvailSizes[2] = new Rectangle(-200, -150, 1200, 900);  // 150%  
        aAvailSizes[3] = new Rectangle(-400, -300, 1600, 1200); // 200%  
       
        // Para utilizr com DVB
        aCropSizes = new Rectangle[4];
        aCropSizes[0] = new Rectangle(0, 0, 800, 600);          // 100%  
        aCropSizes[1] = new Rectangle(0, 0, 800, 600);          // 50%  
        aCropSizes[2] = new Rectangle(100, 150, 600, 450);      // 150%  
        aCropSizes[3] = new Rectangle(200, 200, 400, 400);      // 200%  
      }
     
     
    }

     

     

    Agora, como isso é feito com Java DTV, não sei : )

     

    Atenciosamente,

    Marcos Henke

Concurso ITU-T de Aplicações para IPTV 2012

13 de Agosto de 2012, 19:38, por Desconhecido

Gostaríamos de lembrar aos possíveis interessados que o prazo de registro para participação no Concurso ITU-T de Aplicações para IPTV 2012 (IPTV Application Challenge) se encerra nesta semana, dia 15 de agosto de 2012. Já o prazo para a submissão de aplicações se encerra no dia 07 de setembro de 2012.



NCL Eclipse 1.6 disponível

10 de Janeiro de 2012, 21:19, por Desconhecido

Caros membros da Comunidade Ginga,



Concursos de Aplicações Ginga-NCL

22 de Setembro de 2011, 3:22, por Desconhecido

    Gostaríamos de relembra-los de que há dois concursos de aplicações Ginga-NCL com inscrições ainda abertas. O convite é aberto a toda a comunidade de desenvolvedores de aplicações para o Middleware Ginga-NCL, em nível internacional. São os seguintes concursos:



Novas versões: Ginga e Ginga-NCL Virtual Set-top Box (v.0.12.3)

1 de Agosto de 2011, 20:58, por Desconhecido



Algumas Boas Notícias da Comunidade Ginga

28 de Julho de 2011, 21:31, por Desconhecido

Autor: Roberto Azevedo