| 1919 | } |
| 1920 | |
| 1921 | int RtmpClientStream::Play(const RtmpPlayOptions& opt) { |
| 1922 | if (_rtmpsock == NULL) { |
| 1923 | errno = EPERM; |
| 1924 | return -1; |
| 1925 | } |
| 1926 | if (opt.stream_name.empty()) { |
| 1927 | LOG(ERROR) << "Empty stream_name"; |
| 1928 | errno = EINVAL; |
| 1929 | return -1; |
| 1930 | } |
| 1931 | if (_client_impl == NULL) { |
| 1932 | LOG(ERROR) << "The client stream is not created yet"; |
| 1933 | errno = EPERM; |
| 1934 | return -1; |
| 1935 | } |
| 1936 | butil::IOBuf req_buf; |
| 1937 | { |
| 1938 | butil::IOBufAsZeroCopyOutputStream zc_stream(&req_buf); |
| 1939 | AMFOutputStream ostream(&zc_stream); |
| 1940 | WriteAMFString(RTMP_AMF0_COMMAND_PLAY, &ostream); |
| 1941 | WriteAMFUint32(0, &ostream); |
| 1942 | WriteAMFNull(&ostream); |
| 1943 | WriteAMFString(opt.stream_name, &ostream); |
| 1944 | WriteAMFNumber(opt.start, &ostream); |
| 1945 | WriteAMFNumber(opt.duration, &ostream); |
| 1946 | WriteAMFBool(opt.reset, &ostream); |
| 1947 | CHECK(ostream.good()); |
| 1948 | } |
| 1949 | SocketMessagePtr<policy::RtmpUnsentMessage> msg1(new policy::RtmpUnsentMessage); |
| 1950 | msg1->header.message_length = req_buf.size(); |
| 1951 | msg1->header.message_type = policy::RTMP_MESSAGE_COMMAND_AMF0; |
| 1952 | msg1->header.stream_id = _message_stream_id; |
| 1953 | msg1->chunk_stream_id = _chunk_stream_id; |
| 1954 | msg1->body = req_buf; |
| 1955 | |
| 1956 | if (_client_impl->options().buffer_length_ms > 0) { |
| 1957 | char data[10]; |
| 1958 | char* p = data; |
| 1959 | policy::WriteBigEndian2Bytes( |
| 1960 | &p, policy::RTMP_USER_CONTROL_EVENT_SET_BUFFER_LENGTH); |
| 1961 | policy::WriteBigEndian4Bytes(&p, stream_id()); |
| 1962 | policy::WriteBigEndian4Bytes(&p, _client_impl->options().buffer_length_ms); |
| 1963 | policy::RtmpUnsentMessage* msg2 = policy::MakeUnsentControlMessage( |
| 1964 | policy::RTMP_MESSAGE_USER_CONTROL, data, sizeof(data)); |
| 1965 | msg1->next.reset(msg2); |
| 1966 | } |
| 1967 | // FIXME(gejun): Do we need to SetChunkSize for play? |
| 1968 | // if (_client_impl->options().chunk_size > policy::RTMP_INITIAL_CHUNK_SIZE) { |
| 1969 | // if (SetChunkSize(_client_impl->options().chunk_size) != 0) { |
| 1970 | // return -1; |
| 1971 | // } |
| 1972 | // } |
| 1973 | return _rtmpsock->Write(msg1); |
| 1974 | } |
| 1975 | |
| 1976 | int RtmpClientStream::Play2(const RtmpPlay2Options& opt) { |
| 1977 | butil::IOBuf req_buf; |
no test coverage detected