Skip to content

Commit fa9ea48

Browse files
committed
LibAAH_RTP: Get rid of PipeEvent
Bionic/Android support eventfd, so there is really no reason to have PipeEvent around any more. This change gets rid of it in LibAAH_RTP and replaces it with eventfds. Change-Id: I841fcb71bf5015d521d7517c69f44eac0ea92278 Signed-off-by: John Grossman <johngro@google.com>
1 parent 2921612 commit fa9ea48

File tree

9 files changed

+38
-158
lines changed

9 files changed

+38
-158
lines changed

media/libaah_rtp/Android.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ LOCAL_SRC_FILES := \
1717
aah_tx_group.cpp \
1818
aah_tx_packet.cpp \
1919
aah_tx_player.cpp \
20-
pipe_event.cpp \
2120
utils.cpp
2221

2322
LOCAL_C_INCLUDES := \

media/libaah_rtp/aah_rx_player.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#define LOG_TAG "LibAAH_RTP"
1818
//#define LOG_NDEBUG 0
1919

20+
#include <sys/eventfd.h>
21+
2022
#include <binder/IServiceManager.h>
2123
#include <media/MediaPlayerInterface.h>
2224
#include <utils/Log.h>
@@ -49,6 +51,7 @@ AAH_RXPlayer::AAH_RXPlayer()
4951

5052
memset(&data_source_addr_, 0, sizeof(data_source_addr_));
5153
memset(&transmitter_addr_, 0, sizeof(transmitter_addr_));
54+
wakeup_work_thread_evt_fd_ = eventfd(0, EFD_NONBLOCK);
5255

5356
fetchAudioFlinger();
5457
}
@@ -57,6 +60,10 @@ AAH_RXPlayer::~AAH_RXPlayer() {
5760
reset_l();
5861
CHECK(substreams_.size() == 0);
5962
omx_.disconnect();
63+
64+
if (wakeup_work_thread_evt_fd_ >= 0) {
65+
::close(wakeup_work_thread_evt_fd_);
66+
}
6067
}
6168

6269
status_t AAH_RXPlayer::initCheck() {
@@ -70,6 +77,11 @@ status_t AAH_RXPlayer::initCheck() {
7077
return NO_MEMORY;
7178
}
7279

80+
if (wakeup_work_thread_evt_fd_ < 0) {
81+
LOGE("Failed to allocate wakeup eventfd");
82+
return NO_MEMORY;
83+
}
84+
7385
// Check for the presense of the common time service by attempting to query
7486
// for CommonTime's frequency. If we get an error back, we cannot talk to
7587
// the service at all and should abort now.

media/libaah_rtp/aah_rx_player.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <utils/threads.h>
3131

3232
#include "aah_decoder_pump.h"
33-
#include "pipe_event.h"
3433
#include "utils.h"
3534

3635
namespace android {
@@ -273,7 +272,7 @@ class AAH_RXPlayer : public MediaPlayerInterface {
273272
void sendUnicastGroupLeave();
274273
void fetchAudioFlinger();
275274

276-
PipeEvent wakeup_work_thread_evt_;
275+
int wakeup_work_thread_evt_fd_;
277276
sp<ThreadWrapper> thread_wrapper_;
278277
Mutex api_lock_;
279278
bool is_playing_;

media/libaah_rtp/aah_rx_player_core.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ status_t AAH_RXPlayer::startWorkThread() {
6666

6767
void AAH_RXPlayer::stopWorkThread() {
6868
thread_wrapper_->requestExit(); // set the exit pending flag
69-
wakeup_work_thread_evt_.setEvent();
69+
signalEventFD(wakeup_work_thread_evt_fd_);
7070

7171
status_t res;
7272
res = thread_wrapper_->requestExitAndWait(); // block until thread exit.
7373
if (res != OK) {
7474
LOGE("Failed to stop work thread (res = %d)", res);
7575
}
7676

77-
wakeup_work_thread_evt_.clearPendingEvents();
77+
clearEventFD(wakeup_work_thread_evt_fd_);
7878
}
7979

8080
void AAH_RXPlayer::cleanupSocket() {
@@ -292,7 +292,7 @@ bool AAH_RXPlayer::threadLoop() {
292292
if ((0 != timeout) && (!process_more_right_now)) {
293293
// Set up the events to wait on. Start with the wakeup pipe.
294294
memset(&poll_fds, 0, sizeof(poll_fds));
295-
poll_fds[0].fd = wakeup_work_thread_evt_.getWakeupHandle();
295+
poll_fds[0].fd = wakeup_work_thread_evt_fd_;
296296
poll_fds[0].events = POLLIN;
297297

298298
// Add the RX socket.
@@ -313,7 +313,7 @@ bool AAH_RXPlayer::threadLoop() {
313313
break;
314314
}
315315

316-
wakeup_work_thread_evt_.clearPendingEvents();
316+
clearEventFD(wakeup_work_thread_evt_fd_);
317317
process_more_right_now = false;
318318

319319
// Step 2: Do we have data waiting in the socket? If so, drain the

media/libaah_rtp/aah_tx_group.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -955,20 +955,6 @@ bool AAH_TXGroup::CmdAndControlRXer::init() {
955955
return (mWakeupEventFD >= 0);
956956
}
957957

958-
void AAH_TXGroup::CmdAndControlRXer::wakeupThread() {
959-
if (mWakeupEventFD >= 0) {
960-
uint64_t tmp = 1;
961-
::write(mWakeupEventFD, &tmp, sizeof(tmp));
962-
}
963-
}
964-
965-
void AAH_TXGroup::CmdAndControlRXer::clearWakeupEvent() {
966-
if (mWakeupEventFD >= 0) {
967-
uint64_t tmp;
968-
::read(mWakeupEventFD, &tmp, sizeof(tmp));
969-
}
970-
}
971-
972958
bool AAH_TXGroup::CmdAndControlRXer::threadLoop() {
973959
// Implementation for main command and control receiver thread. Its primary
974960
// job is to service command and control requests from clients. These
@@ -1053,8 +1039,9 @@ bool AAH_TXGroup::CmdAndControlRXer::threadLoop() {
10531039
}
10541040

10551041
// clear the wakeup event if needed.
1056-
if (pollFds[0].revents)
1057-
clearWakeupEvent();
1042+
if (pollFds[0].revents) {
1043+
clearEventFD(mWakeupEventFD);
1044+
}
10581045

10591046
// Handle any pending C&C requests and heartbeat timeouts. Also, trim the
10601047
// retry buffers if its time to do so.

media/libaah_rtp/aah_tx_group.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,14 @@ class AAH_TXGroup : public virtual RefBase {
127127
class CmdAndControlRXer : public Thread {
128128
public:
129129
CmdAndControlRXer();
130-
void wakeupThread();
131130
bool init();
131+
void wakeupThread() { signalEventFD(mWakeupEventFD); }
132132

133133
protected:
134134
virtual ~CmdAndControlRXer();
135135

136136
private:
137137
virtual bool threadLoop();
138-
void clearWakeupEvent();
139138

140139
static const int kMaxReceiverPacketLen;
141140
static const uint32_t kRetryRequestID;

media/libaah_rtp/pipe_event.cpp

Lines changed: 0 additions & 86 deletions
This file was deleted.

media/libaah_rtp/pipe_event.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

media/libaah_rtp/utils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#ifndef __UTILS_H__
1818
#define __UTILS_H__
1919

20+
#include <stdint.h>
21+
#include <unistd.h>
22+
2023
#include <netinet/in.h>
2124

2225
#include <media/stagefright/foundation/ABase.h>
@@ -80,6 +83,20 @@ inline int minTimeout(int a, int b) {
8083
return ((a < b) ? a : b);
8184
}
8285

86+
inline void signalEventFD(int fd) {
87+
if (fd >= 0) {
88+
uint64_t tmp = 1;
89+
::write(fd, &tmp, sizeof(tmp));
90+
}
91+
}
92+
93+
inline void clearEventFD(int fd) {
94+
if (fd >= 0) {
95+
uint64_t tmp;
96+
::read(fd, &tmp, sizeof(tmp));
97+
}
98+
}
99+
83100
} // namespace android
84101

85102
#endif // __UTILS_H__

0 commit comments

Comments
 (0)