コード例 #1
0
  public void stopCallback(ErrorCode ret) {
    if (ErrorCode.succeeded(ret)) {
      m_VideoParams = null;
      m_AudioParams = null;

      cleanupBuffers();

      try {
        if (m_Listener != null) {
          m_Listener.onBroadcastStopped();
        }
      } catch (Exception x) {
        reportError(x.toString());
      }

      if (m_LoggedIn) {
        setBroadcastState(BroadcastState.ReadyToBroadcast);
      } else {
        setBroadcastState(BroadcastState.Initialized);
      }
    } else {
      // there's not really a good state to go into here
      setBroadcastState(BroadcastState.ReadyToBroadcast);

      String err = ErrorCode.getString(ret);
      reportError(String.format("stopCallback got failure: %s", err));
    }
  }
コード例 #2
0
  public ErrorCode submitFrame(FrameBuffer bgraFrame) {
    if (this.getIsPaused()) {
      resumeBroadcasting();
    } else if (!this.getIsBroadcasting()) {
      return ErrorCode.TTV_EC_STREAM_NOT_STARTED;
    }

    ErrorCode ret = m_Stream.submitVideoFrame(bgraFrame);

    // if there is a problem when submitting a frame let the client know
    if (ret != ErrorCode.TTV_EC_SUCCESS) {
      String err = ErrorCode.getString(ret);
      if (ErrorCode.succeeded(ret)) {
        reportWarning(String.format("Warning in SubmitTexturePointer: %s\n", err));
      } else {
        reportError(String.format("Error in SubmitTexturePointer: %s\n", err));

        // errors are not recoverable
        stopBroadcasting();
      }

      if (m_Listener != null) {
        m_Listener.onframeSubmissionIssue(ret);
      }
    }

    return ret;
  }
コード例 #3
0
 /**
  * Requests a list of all games matching the given search string. The result will be returned
  * asynchronously via OnGameNameListReceived.
  *
  * @param str Whether or not the request was made
  */
 public void requestGameNameList(String str) {
   ErrorCode ret = m_Stream.getGameNameList(str);
   if (ErrorCode.failed(ret)) {
     String err = ErrorCode.getString(ret);
     reportError(String.format("Error in GetGameNameList: %s\n", err));
   }
 }
コード例 #4
0
  public void getUserInfoCallback(ErrorCode result, UserInfo userInfo) {
    m_UserInfo = userInfo;

    if (ErrorCode.failed(result)) {
      String err = ErrorCode.getString(result);
      reportError(String.format("UserInfoDoneCallback got failure: %s", err));
    }
  }
コード例 #5
0
  protected boolean checkError(ErrorCode err) {
    if (ErrorCode.failed(err)) {
      reportError(ErrorCode.getString(err));
      return false;
    }

    return true;
  }
コード例 #6
0
 public String getJson() {
   JsonObject jsobj = new JsonObject();
   if (errorMsg == null) {
     jsobj.add("errorCode", new JsonPrimitive(errorCode.name()));
     jsobj.add("errorMsg", new JsonPrimitive("null"));
   } else {
     jsobj.add("errorCode", new JsonPrimitive(errorCode.name()));
     jsobj.add("errorMsg", new JsonPrimitive(errorMsg));
   }
   return jsobj.toString();
 }
コード例 #7
0
  /**
   * Use this in place of valueOf.
   *
   * @param value real value
   * @return ErrorCode corresponding to the value
   */
  public static ErrorCode fromValue(String value) {
    if (value == null || "".equals(value)) {
      throw new IllegalArgumentException("Value cannot be null or empty!");
    }

    for (ErrorCode enumEntry : ErrorCode.values()) {
      if (enumEntry.toString().equals(value)) {
        return enumEntry;
      }
    }

    throw new IllegalArgumentException("Cannot create enum from " + value + " value!");
  }
コード例 #8
0
  /**
   * Send a singular action metadata point to Twitch's metadata service.
   *
   * @param name A specific name for an event meant to be queryable
   * @param streamTime Number of milliseconds into the broadcast for when event occurs
   * @param humanDescription Long form string to describe the meaning of an event. Maximum length is
   *     1000 characters
   * @param data A valid JSON object that is the payload of an event. Values in this JSON object
   *     have to be strings. Maximum of 50 keys are allowed. Maximum length for values are 255
   *     characters.
   * @return True if submitted and no error, false otherwise.
   */
  public boolean sendActionMetaData(
      String name, long streamTime, String humanDescription, String data) {
    ErrorCode ret =
        m_Stream.sendActionMetaData(m_AuthToken, name, streamTime, humanDescription, data);
    if (ErrorCode.failed(ret)) {
      String err = ErrorCode.getString(ret);
      reportError(String.format("Error while sending meta data: %s\n", err));

      return false;
    }

    return true;
  }
コード例 #9
0
  public void getGameNameListCallback(ErrorCode result, GameInfoList list) {
    if (ErrorCode.failed(result)) {
      String err = ErrorCode.getString(result);
      reportError(String.format("GameNameListCallback got failure: %s", err));
    }

    try {
      if (m_Listener != null) {
        m_Listener.onGameNameListReceived(result, list == null ? new GameInfo[0] : list.list);
      }
    } catch (Exception x) {
      reportError(x.toString());
    }
  }
コード例 #10
0
  /**
   * Sets the visible data about the channel of the currently logged in user.
   *
   * @param channel The name of the channel.
   * @param game The name of the game. If the empty string or null then this parameter is ignored.
   * @param title The title of the channel. If the empty string or null then this parameter is
   *     ignored.
   * @return Whether or not the request was made
   */
  public boolean setStreamInfo(String channel, String game, String title) {
    if (!m_LoggedIn) {
      return false;
    }

    if (channel == null || channel == "") {
      channel = m_UserName;
    }

    if (game == null) {
      game = "";
    }

    if (title == null) {
      title = "";
    }

    StreamInfoForSetting info = new StreamInfoForSetting();
    info.streamTitle = title;
    info.gameName = game;

    ErrorCode err = m_Stream.setStreamInfo(m_AuthToken, channel, info);
    checkError(err);

    return ErrorCode.succeeded(err);
  }
コード例 #11
0
  /** Initializes the SDK and the controller. */
  public boolean initializeTwitch() {
    if (m_SdkInitialized) {
      return false;
    }

    String dllPath = m_DllPath;
    if (dllPath == "") {
      dllPath = "./";
    }

    m_Stream.setStreamCallbacks(this);

    ErrorCode err = m_Stream.initialize(m_ClientId, VideoEncoder.TTV_VID_ENC_DEFAULT, dllPath);
    if (!checkError(err)) {
      m_Stream.setStreamCallbacks(null);
      return false;
    }

    err = m_Stream.setTraceLevel(MessageLevel.TTV_ML_ERROR);
    if (!checkError(err)) {
      m_Stream.setStreamCallbacks(null);
      return false;
    }

    if (ErrorCode.succeeded(err)) {
      m_SdkInitialized = true;
      setBroadcastState(BroadcastState.Initialized);
      return true;
    }

    return false;
  }
コード例 #12
0
  /**
   * Terminates the broadcast.
   *
   * @return Whether or not successfully stopped
   */
  public boolean stopBroadcasting() {
    if (!this.getIsBroadcasting()) {
      return false;
    }

    ErrorCode ret = m_Stream.stop(true);
    if (ErrorCode.failed(ret)) {
      String err = ErrorCode.getString(ret);
      reportError(String.format("Error while stopping the broadcast: %s", err));
      return false;
    }

    setBroadcastState(BroadcastState.Stopping);

    return ErrorCode.succeeded(ret);
  }
コード例 #13
0
ファイル: Gears.java プロジェクト: RELO4D3D/sdk-dist
 public void onLoginAttemptComplete(ErrorCode result) {
   if (ErrorCode.succeeded(result)) {
     if (enableChat) {
       initChat();
     }
   }
 }
コード例 #14
0
  public void getArchivingStateCallback(ErrorCode result, ArchivingState state) {
    m_ArchivingState = state;

    if (ErrorCode.failed(result)) {
      // String err = ErrorCode.getString(result);
      // reportWarning(String.Format("ArchivingStateDoneCallback got failure: {0}", err));
    }
  }
コード例 #15
0
ファイル: ErrorUtils.java プロジェクト: editice/cmsb
  /** 初始化 string2ErrorCodeMap,errorMap */
  static {
    for (ErrorCode errorCode : ErrorCode.values()) {
      string2ErrorCodeMap.put(errorCode.name(), errorCode);
    }

    for (String errorFile : errorFiles) {
      InputStream in = null;
      try {
        in = ErrorUtils.class.getClassLoader().getResourceAsStream(errorFile);
        errorMap.putAll(ErrorDOLoader.loadXml(in));
      } finally {
        if (in != null) {
          IOUtils.closeQuietly(in);
        }
      }
    }
  }
コード例 #16
0
  protected void updateStreamInfo() {
    long now = System.nanoTime();
    long delta = (now - m_LastStreamInfoUpdateTime) / 1000000000;

    // only check every so often
    if (delta < s_StreamInfoUpdateInterval) {
      return;
    }

    m_LastStreamInfoUpdateTime = now;

    ErrorCode ret = m_Stream.getStreamInfo(m_AuthToken, m_UserName);
    if (ErrorCode.failed(ret)) {
      String err = ErrorCode.getString(ret);
      reportError(String.format("Error in TTV_GetStreamInfo: %s", err));
    }
  }
コード例 #17
0
ファイル: Gears.java プロジェクト: RELO4D3D/sdk-dist
 public void onGameNameListReceived(ErrorCode result, GameInfo[] list) {
   if (ErrorCode.succeeded(result)) {
     System.out.println("Game names:");
     for (int i = 0; i < list.length; ++i) {
       System.out.println("    " + list[i].name);
     }
   }
 }
コード例 #18
0
  /**
   * Pauses the current broadcast and displays the default pause screen.
   *
   * @return Whether or not successfully paused
   */
  public boolean pauseBroadcasting() {
    if (!this.getIsBroadcasting()) {
      return false;
    }

    ErrorCode ret = m_Stream.pauseVideo();
    if (ErrorCode.failed(ret)) {
      // not streaming anymore
      stopBroadcasting();

      String err = ErrorCode.getString(ret);
      reportError(String.format("Error pausing stream: %s\n", err));
    } else {
      setBroadcastState(BroadcastState.Paused);
    }

    return ErrorCode.succeeded(ret);
  }
コード例 #19
0
  /**
   * Runs a commercial on the channel. Must be broadcasting.
   *
   * @return Whether or not successful
   */
  public boolean runCommercial() {
    if (!this.getIsBroadcasting()) {
      return false;
    }

    ErrorCode err = m_Stream.runCommercial(m_AuthToken);
    checkError(err);

    return ErrorCode.succeeded(err);
  }
コード例 #20
0
  /**
   * Send the ending datapoint of an event that has a beginning and end.
   *
   * @param name A specific name for an event meant to be queryable
   * @param streamTime Number of milliseconds into the broadcast for when event occurs
   * @param sequenceId Associates a start and end event together. Use the corresponding sequenceId
   *     returned in TTV_SendStartSpanMetaData
   * @param humanDescription Long form string to describe the meaning of an event. Maximum length is
   *     1000 characters
   * @param data A valid JSON object that is the payload of an event. Values in this JSON object
   *     have to be strings. Maximum of 50 keys are allowed. Maximum length for values are 255
   *     characters.
   * @return True if submitted and no error, false otherwise.
   */
  public boolean endSpanMetaData(
      String name, long streamTime, long sequenceId, String humanDescription, String data) {
    if (sequenceId == -1) {
      reportError(String.format("Invalid sequence id: %d\n", sequenceId));
      return false;
    }

    ErrorCode ret =
        m_Stream.sendEndSpanMetaData(
            m_AuthToken, name, streamTime, sequenceId, humanDescription, data);
    if (ErrorCode.failed(ret)) {
      String err = ErrorCode.getString(ret);
      reportError(String.format("Error in SendStopSpanMetaData: %s\n", err));

      return false;
    }

    return true;
  }
コード例 #21
0
ファイル: Http2.java プロジェクト: ihrthk/okhttp
 private void readRstStream(Handler handler, int length, byte flags, int streamId)
     throws IOException {
   if (length != 4) throw ioException("TYPE_RST_STREAM length: %d != 4", length);
   if (streamId == 0) throw ioException("TYPE_RST_STREAM streamId == 0");
   int errorCodeInt = source.readInt();
   ErrorCode errorCode = ErrorCode.fromHttp2(errorCodeInt);
   if (errorCode == null) {
     throw ioException("TYPE_RST_STREAM unexpected error code: %d", errorCodeInt);
   }
   handler.rstStream(streamId, errorCode);
 }
コード例 #22
0
  /**
   * Returns a fully populated VideoParams struct based on the given width, height and frame rate.
   * This function is not the advised way to setup VideoParams because it has no information about
   * the user's maximum bitrate. Use the other version of GetRecommendedVideoParams instead if
   * possible.
   *
   * @param width The broadcast width
   * @param height The broadcast height
   * @param frameRate The broadcast frames per second
   * @return The VideoParams
   */
  public VideoParams getRecommendedVideoParams(int width, int height, int frameRate) {
    VideoParams videoParams = new VideoParams();

    videoParams.outputWidth = width;
    videoParams.outputHeight = height;
    videoParams.targetFps = frameRate;
    videoParams.pixelFormat = determinePixelFormat();
    videoParams.encodingCpuUsage = EncodingCpuUsage.TTV_ECU_HIGH;
    videoParams.disableAdaptiveBitrate = false;
    videoParams.verticalFlip = false;

    // Compute the rest of the fields based on the given parameters
    ErrorCode ret = m_Stream.getDefaultParams(videoParams);
    if (ErrorCode.failed(ret)) {
      String err = ErrorCode.getString(ret);
      reportError(String.format("Error in GetDefaultParams: %s", err));
      return null;
    }

    return videoParams;
  }
コード例 #23
0
  public void startCallback(ErrorCode ret) {
    if (ErrorCode.succeeded(ret)) {
      try {
        if (m_Listener != null) {
          m_Listener.onBroadcastStarted();
        }
      } catch (Exception x) {
        reportError(x.toString());
      }

      setBroadcastState(BroadcastState.Broadcasting);
    } else {
      m_VideoParams = null;
      m_AudioParams = null;

      setBroadcastState(BroadcastState.ReadyToBroadcast);

      String err = ErrorCode.getString(ret);
      reportError(String.format("startCallback got failure: %s", err));
    }
  }
コード例 #24
0
  public void loginCallback(ErrorCode result, ChannelInfo channelInfo) {
    if (ErrorCode.succeeded(result)) {
      m_ChannelInfo = channelInfo;
      setBroadcastState(BroadcastState.LoggedIn);
      m_LoggedIn = true;
    } else {
      setBroadcastState(BroadcastState.Initialized);
      m_LoggedIn = false;

      String err = ErrorCode.getString(result);
      reportError(String.format("LoginCallback got failure: %s", err));
    }

    try {
      if (m_Listener != null) {
        m_Listener.onLoginAttemptComplete(result);
      }
    } catch (Exception x) {
      reportError(x.toString());
    }
  }
コード例 #25
0
  public void requestAuthTokenCallback(ErrorCode result, AuthToken authToken) {
    if (ErrorCode.succeeded(result)) {
      // Now that the user is authorized the information can be requested about which server to
      // stream to
      m_AuthToken = authToken;
      setBroadcastState(BroadcastState.Authenticated);
    } else {
      m_AuthToken.data = "";
      setBroadcastState(BroadcastState.Initialized);

      String err = ErrorCode.getString(result);
      reportError(String.format("RequestAuthTokenDoneCallback got failure: %s", err));
    }

    try {
      if (m_Listener != null) {
        m_Listener.onAuthTokenRequestComplete(result, authToken);
      }
    } catch (Exception x) {
      reportError(x.toString());
    }
  }
コード例 #26
0
  /**
   * Begins broadcast using the given VideoParams.
   *
   * @param videoParams The video params
   * @return Whether or not successfully broadcasting
   */
  public boolean startBroadcasting(VideoParams videoParams) {
    if (videoParams == null || !this.getIsReadyToBroadcast()) {
      return false;
    }

    m_VideoParams = videoParams.clone();

    // Setup the audio parameters
    m_AudioParams = new AudioParams();
    m_AudioParams.audioEnabled =
        m_EnableAudio && getIsAudioSupported(); // // only enable audio if possible

    if (!allocateBuffers()) {
      m_VideoParams = null;
      m_AudioParams = null;
      return false;
    }

    ErrorCode ret =
        m_Stream.start(videoParams, m_AudioParams, m_IngestServer, StartFlags.None, true);
    if (ErrorCode.failed(ret)) {
      cleanupBuffers();

      String err = ErrorCode.getString(ret);
      reportError(String.format("Error while starting to broadcast: %s", err));

      m_VideoParams = null;
      m_AudioParams = null;

      return false;
    }

    setBroadcastState(BroadcastState.Starting);

    return true;
  }
コード例 #27
0
 private void readGoAway(Handler handler, int flags, int length, int streamId)
     throws IOException {
   if (length < 8) throw ioException("TYPE_GOAWAY length < 8: %s", length);
   int lastStreamId = in.readInt();
   int errorCodeInt = in.readInt();
   int opaqueDataLength = length - 8;
   ErrorCode errorCode = ErrorCode.fromHttp2(errorCodeInt);
   if (errorCode == null) {
     throw ioException("TYPE_RST_STREAM unexpected error code: %d", errorCodeInt);
   }
   if (Util.skipByReading(in, opaqueDataLength) != opaqueDataLength) {
     throw new IOException("TYPE_GOAWAY opaque data was truncated");
   }
   handler.goAway(lastStreamId, errorCode);
 }
コード例 #28
0
  public void getIngestServersCallback(ErrorCode result, IngestList ingestList) {
    if (ErrorCode.succeeded(result)) {
      m_IngestList = ingestList;

      // assume we're going to use the default ingest server unless overridden by the client
      m_IngestServer = m_IngestList.getDefaultServer();

      setBroadcastState(BroadcastState.ReceivedIngestServers);

      try {
        if (m_Listener != null) {
          m_Listener.onIngestListReceived(ingestList);
        }
      } catch (Exception x) {
        reportError(x.toString());
      }
    } else {
      String err = ErrorCode.getString(result);
      reportError(String.format("IngestListCallback got failure: %s", err));

      // try again
      setBroadcastState(BroadcastState.LoggingIn);
    }
  }
コード例 #29
0
 private void readRstStream(FrameReader.Handler paramHandler, int paramInt1, byte paramByte, int paramInt2)
 {
   if (paramInt1 != 4) {
     throw Http2.ioException("TYPE_RST_STREAM length: %d != 4", new Object[] { Integer.valueOf(paramInt1) });
   }
   if (paramInt2 == 0) {
     throw Http2.ioException("TYPE_RST_STREAM streamId == 0", new Object[0]);
   }
   paramInt1 = this.source.readInt();
   ErrorCode localErrorCode = ErrorCode.fromHttp2(paramInt1);
   if (localErrorCode == null) {
     throw Http2.ioException("TYPE_RST_STREAM unexpected error code: %d", new Object[] { Integer.valueOf(paramInt1) });
   }
   paramHandler.rstStream(paramInt2, localErrorCode);
 }
コード例 #30
0
  public void getStreamInfoCallback(ErrorCode result, StreamInfo streamInfo) {
    if (ErrorCode.succeeded(result)) {
      m_StreamInfo = streamInfo;

      try {
        if (m_Listener != null) {
          m_Listener.onStreamInfoUpdated(streamInfo);
        }
      } catch (Exception x) {
        reportError(x.toString());
      }
    } else {
      // String err = ErrorCode.getString(result);
      // reportWarning(String.Format("StreamInfoDoneCallback got failure: {0}", err));
    }
  }