Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to createAnswer to recive video and audio #1259

Open
HavenBaby opened this issue Sep 25, 2024 · 2 comments
Open

How to createAnswer to recive video and audio #1259

HavenBaby opened this issue Sep 25, 2024 · 2 comments

Comments

@HavenBaby
Copy link

I see that most of the examples are based on addtrack, but I haven't seen any examples of ontrack receiving audio and video. Could you provide an example of an answer method for receiving audio and video?

@shichunsheng1993
Copy link

Has your problem been solved?Can you tell me how to solve it?

@paullouisageneau
Copy link
Owner

If you already know what you want to send or receive, for instance because your media pipeline is fixed, you really should offer. However, if it is necessary, you can answer and get the remotely-offered track with onTrack(). In this case, you need to check what the remote peer offers:

std::shared_ptr<rtc::Track> track;
pc->onTrack([&track](std::shared_ptr<Track> offeredTrack) {
    auto desc = offeredTrack->description();
    if (desc.direction() == rtc::Description::Direction::SendOnly)
        return;

    // Filter formats we can receive
    for(int pt : desc.payloadTypes()) {
        auto rtpMap = desc.rtpMap(pt);
        // If you don't want to receive this format, remove it from the description with desc.removeRtpMap(pt)
        // If you want to receive this format, you can optionally set an RTP depacketizer for pt with track->setMediaHandler()
   }
   
   offeredTrack->setDescription(desc);
   std::atomic_store(&track, offeredTrack);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants