Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. static Bin newPlayBin(RSBin bin, String fileName, long fadeoutStartTime, double gain){
  2.  
  3. String name = bin.getName()+(playBinCount++);
  4. Bin playBin = null;
  5.  
  6. try{
  7. logger.debug("InitPreview: Initializing Preview Bin.");
  8. //Pipeline playPipe = new Pipeline(name+PIPELINE);
  9. playBin = new Bin(name+BIN);
  10.  
  11. final Element source = ElementFactory.make("filesrc", name+SOURCE);
  12. final DecodeBin decodeBin = new DecodeBin (name+"Decode");
  13.  
  14. final Element audioConvert = ElementFactory.make("audioconvert", name+AUDIOCONVERT);
  15.  
  16.  
  17. decodeBin.connect(new DecodeBin.NEW_DECODED_PAD(){
  18. public void newDecodedPad(Element element, Pad pad, boolean last){
  19. decodeBin.link(audioConvert);
  20. }
  21. });
  22.  
  23. Element resample = ElementFactory.make(resampler, name+RESAMPLE);
  24. //Element rgVolume = ElementFactory.make("rgvolume", name+"RGVolume");
  25. Element volume = ElementFactory.make("volume", name+VOLUME);
  26.  
  27. Double binVolume = bin.getVolume() * dBToLinear(gain);
  28.  
  29. volume.set("volume", Double.toString(binVolume));
  30. logger.debug("SETTING VOLUME TO: "+binVolume);
  31.  
  32. String mixer = null, deviceName = null;
  33. String resourceType = null;
  34. if (bin == RSBin.PLAYOUT)
  35. resourceType = AudioService.PLAYOUT;
  36. else
  37. resourceType = AudioService.PREVIEW;
  38.  
  39. ResourceConfig resourceConfig = getResourceConfig(RSController.AUDIO_SERVICE, resourceType);
  40. mixer = resourceConfig.resourceMixer();
  41. deviceName = resourceConfig.resourceDeviceName();
  42.  
  43. Element playSink = getAudioSink(mixer, deviceName, name);
  44.  
  45. logger.info("NewPlayBin: Using sink mixer: "+mixer+" deviceName: "+deviceName + " type: "+resourceType);
  46.  
  47. playBin.addMany(source, decodeBin, audioConvert, resample, /*rgVolume,*/ volume, playSink);
  48. playBin.linkMany(source, decodeBin);
  49. playBin.linkMany(audioConvert, resample, /*rgVolume,*/ volume, playSink);
  50.  
  51. playBin.setState(State.NULL);
  52.  
  53. pipe.add(playBin);
  54. //playPipe.add(playBin);
  55.  
  56.  
  57. if (playBinCount == 1){
  58. Bus bus = playBin.getBus();
  59. //Bus bus = playPipe.getBus();
  60.  
  61.  
  62. Bus.STATE_CHANGED stateChanged = new Bus.STATE_CHANGED(){
  63. public void stateChanged(GstObject source, State old, State cur, State pending){
  64. stateHandler.stateChanged(source, old, cur, pending);
  65. }
  66. };
  67.  
  68. bus.connect(stateChanged);
  69.  
  70. Bus.EOS eos = new Bus.EOS(){
  71. public void endOfStream(GstObject source){
  72. logger.info("EndOfStream: EOS received from: "+source);
  73. handleEOS(source);
  74. }
  75. };
  76.  
  77. bus.connect(eos);
  78.  
  79. Bus.ERROR error = new Bus.ERROR(){
  80. public void errorMessage(GstObject source, int code, String message){
  81. handleError(source, message);
  82. }
  83. };
  84.  
  85. bus.connect(error);
  86.  
  87. Bus.TAG tag = new Bus.TAG(){
  88. public void tagsFound(GstObject source, TagList tagList){
  89. handleTags(source, tagList);
  90. }
  91. };
  92.  
  93. bus.connect(tag);
  94. }
  95.  
  96. bin.setInit();
  97.  
  98. rsBins.put(playBin, bin);
  99.  
  100.  
  101. PlayBinInfo binInfo = new PlayBinInfo(bin, playBin, fadeoutStartTime);
  102. playBinInfos.put(playBin, binInfo);
  103.  
  104. return playBin;
  105. /*
  106. rsBins.put(playPipe, bin);
  107.  
  108. PlayBinInfo binInfo = new PlayBinInfo(bin, playPipe, fadeoutStartTime);
  109. playBinInfos.put(playPipe, binInfo);
  110. return playPipe;
  111. */
  112. } catch (Exception e) {
  113. logger.error("InitPreview: Could not initialize.", e);
  114. return null;
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement