Mike J. Chen 06e04e4c17 Add media/libaah_rtp
RTP library used to broadcast media from one device to a collection
of listeners.  Handles failures/retries/etc.

This is a squashed merge from master-tungsten of the following changes:

commit e1a5101fe627d71739a7c4263bb3a65c7bc44385
Author: Jason Simmons <jsimmons@google.com>
Date:   Fri Aug 12 13:24:21 2011 -0700

    Hold ThreadWrapper in a ref-counting pointer

    Change-Id: Iaf3343182e37bcc0ca99fbaf8f9bbb8c4984072a

commit 89b90d62e164ff3db27c9cba85255fc476d2dd96
Author: Jason Simmons <jsimmons@google.com>
Date:   Wed Aug 10 13:08:25 2011 -0700

    Update the Tungsten TX player to use HTTPBase

    Change-Id: I9f7ecf1b4b496cec1815284dbcdb958a43284169

commit 43be3231034ff8537fdd84422a7954780038671f
Author: John Grossman <johngro@google.com>
Date:   Mon Jun 27 18:59:12 2011 -0700

    Move libaah_rtp over from the vendor directory.

    Also move factor PipeEvent out into utils.

    Change-Id: Id3877c66efe22d771cf3ef4877107e431b828e37

Change-Id: I5fe1ea941c09204d7b33f15f4e2b2ab320dc468b
Signed-off-by: Mike J. Chen <mjchen@google.com>
Signed-off-by: John Grossman <johngro@google.com>
Signed-off-by: Jason Simmons <jsimmons@google.com>
2011-10-28 10:14:49 -04:00

87 lines
1.9 KiB
C++

/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "LibAAH_RTP"
#include <utils/Log.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <unistd.h>
#include "pipe_event.h"
namespace android {
PipeEvent::PipeEvent() {
pipe_[0] = -1;
pipe_[1] = -1;
// Create the pipe.
if (pipe(pipe_) >= 0) {
// Set non-blocking mode on the read side of the pipe so we can
// easily drain it whenever we wakeup.
fcntl(pipe_[0], F_SETFL, O_NONBLOCK);
} else {
LOGE("Failed to create pipe event %d %d %d",
pipe_[0], pipe_[1], errno);
pipe_[0] = -1;
pipe_[1] = -1;
}
}
PipeEvent::~PipeEvent() {
if (pipe_[0] >= 0) {
close(pipe_[0]);
}
if (pipe_[1] >= 0) {
close(pipe_[1]);
}
}
void PipeEvent::clearPendingEvents() {
char drain_buffer[16];
while (read(pipe_[0], drain_buffer, sizeof(drain_buffer)) > 0) {
// No body.
}
}
bool PipeEvent::wait(int timeout) {
struct pollfd wait_fd;
wait_fd.fd = getWakeupHandle();
wait_fd.events = POLLIN;
wait_fd.revents = 0;
int res = poll(&wait_fd, 1, timeout);
if (res < 0) {
LOGE("Wait error in PipeEvent; sleeping to prevent overload!");
usleep(1000);
}
return (res > 0);
}
void PipeEvent::setEvent() {
char foo = 'q';
write(pipe_[1], &foo, 1);
}
} // namespace android