Giter Club home page Giter Club logo

Comments (9)

Reedyuk avatar Reedyuk commented on September 27, 2024

I'm in the same boat as you, i have tried several guides and they all seem to not build correctly.
Apparently the webrtc code runs hot on lower end devices, you should check out the google code forum about it.

from apprtc-ios.

pochuang avatar pochuang commented on September 27, 2024

Originally, I doubt the high fps (up to 44 or higher) can be the reason. Finally I feel disappointed when I try to lower the frame rate using the codes below. The CPU usage still goes to 120% or even higher!

  • (RTCMediaConstraints )defaultMediaStreamConstraints {
    NSArray *mandatoryConstraints = @[
    [[RTCPair alloc] initWithKey:@"maxHeight" value:[NSString stringWithFormat:@"%d",self.maxHeight]],
    [[RTCPair alloc] initWithKey:@"maxWidth" value:[NSString stringWithFormat:@"%d",self.maxWidth]],
    [[RTCPair alloc] initWithKey:@"maxFrameRate" value:[NSString stringWithFormat:@"%d",self.maxFrameRate]],
    [[RTCPair alloc] initWithKey:@"minFrameRate" value:[NSString stringWithFormat:@"%d",self.minFrameRate]]
    ];
    RTCMediaConstraints
    theConstraints =
    [[RTCMediaConstraints alloc]
    initWithMandatoryConstraints:mandatoryConstraints
    optionalConstraints:@[@"frameRate":@"15"]];
    return theConstraints;
    }

However, there is some evidence that the renderer can be the cause due to the following site:

https://perch.co/blog/perchrtc-custom-webrtc-rendering/

I would give a try if there is any progress and share with you guys.

from apprtc-ios.

Reedyuk avatar Reedyuk commented on September 27, 2024

i have decided to use opentok, their library works perfect for webrtc, but you have to go through them.

from apprtc-ios.

kos9kus avatar kos9kus commented on September 27, 2024

pochuang,
You mean that the webRtc lib ignores an initialization of mandatoryConstraints ?

from apprtc-ios.

pochuang avatar pochuang commented on September 27, 2024

Finally, I found that the AVCaptureSession could be the reason why my iphone is burning! Before this adjustment, the cpu usage is always 120% or higher, but after this it drops down to 70%! This is a very huge change although it's not a very great solution. The magic is to set sessionPreset to low like this:

  • (RTCMediaConstraints *)defaultMediaStreamConstraints {

    static RTCMediaConstraints *defaultMediaStreamConstraints;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    NSArray *mandatoryConstraints = @[
    [[RTCPair alloc] initWithKey:@"maxHeight" value:[NSString stringWithFormat:@"%d",self.maxHeight]],
    [[RTCPair alloc] initWithKey:@"maxWidth" value:[NSString stringWithFormat:@"%d",self.maxWidth]],
    [[RTCPair alloc] initWithKey:@"minWidth" value:[NSString stringWithFormat:@"%d",self.minWidth]],
    [[RTCPair alloc] initWithKey:@"minHeight" value:[NSString stringWithFormat:@"%d",self.minWidth]],
    [[RTCPair alloc] initWithKey:@"maxFrameRate" value:[NSString stringWithFormat:@"%d",self.maxFrameRate]],
    [[RTCPair alloc] initWithKey:@"minFrameRate" value:[NSString stringWithFormat:@"%d",self.minFrameRate]]
    ];

    NSArray *optionalConstraints = @[];
    
    defaultMediaStreamConstraints =
    [[RTCMediaConstraints alloc]
     initWithMandatoryConstraints:mandatoryConstraints
     optionalConstraints:optionalConstraints];        
    

    });

    return defaultMediaStreamConstraints;
    }

#if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE
RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints];
RTCAVFoundationVideoSource *source =
[[RTCAVFoundationVideoSource alloc] initWithFactory:_factory
constraints:mediaConstraints];
if ([source.captureSession canSetSessionPreset:AVCaptureSessionPresetLow]) {
source.captureSession.sessionPreset = AVCaptureSessionPresetLow;
}
#endif

I am still working on this for a better solution. If you have any idea here, please let me know.

from apprtc-ios.

kos9kus avatar kos9kus commented on September 27, 2024

Please make a pull request for more details, what are values your self.maxHeight, self.minWidth etc..? The values is important and affect on a performance of CPU.
And does it make sense to use a "dispatch_once" ? I would like to contribute towards it, because I look into this problem.

from apprtc-ios.

pochuang avatar pochuang commented on September 27, 2024

The accepted values are listed below:

#define DEFAULT_MAX_HEIGHT 960
#define DEFAULT_MAX_WIDTH 720
#define DEFAULT_MIN_FRAME_RATE 5
#define DEFAULT_MAX_FRAME_RATE 12
#define ENABLE_BOOST_PERFORMANCE YES

The minWidth and minHeight do not work, so I modified it like this:

- (RTCMediaConstraints *)defaultMediaStreamConstraints {
    NSArray *mandatoryConstraints = @[
                                      [[RTCPair alloc] initWithKey:@"maxHeight" value:[NSString stringWithFormat:@"%d",self.maxHeight]],
                                      [[RTCPair alloc] initWithKey:@"maxWidth" value:[NSString stringWithFormat:@"%d",self.maxWidth]],
                                      [[RTCPair alloc] initWithKey:@"maxFrameRate" value:[NSString stringWithFormat:@"%d",self.maxFrameRate]],
                                      [[RTCPair alloc] initWithKey:@"minFrameRate" value:[NSString stringWithFormat:@"%d",self.minFrameRate]]
                                      ];
    
    NSArray *optionalConstraints = @[];
    
    RTCMediaConstraints* theConstraints =
    [[RTCMediaConstraints alloc]
     initWithMandatoryConstraints:mandatoryConstraints
     optionalConstraints:optionalConstraints];
    return theConstraints;
}

And the sessionPreset part like this:

#if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE
    RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints];
    RTCAVFoundationVideoSource *source =
    [[RTCAVFoundationVideoSource alloc] initWithFactory:_factory
                                            constraints:mediaConstraints];
    if(ENABLE_BOOST_PERFORMANCE){
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{            
            if ([source.captureSession canSetSessionPreset:AVCaptureSessionPresetLow]) {
                [source.captureSession stopRunning];
                source.captureSession.sessionPreset = AVCaptureSessionPresetLow;
                [source.captureSession startRunning];
            }
        });
    }
    videoTrack =
    [[RTCVideoTrack alloc] initWithFactory:_factory
                                    source:source
                                   trackId:@"ARDAMSv0"];
#endif
WebRTC will change sessionPreset due to your device's resolution at first. That will make your video more clear but become heavy to CPU. You may take a look at the source code downloaded from google.

The video resolution and frame rate you received from others will also affect CPU in iPhone. For me, I reduce it to 640x480.

Now the CPU usage is down to 58% or a little higher than 60%. Not pretty satisfying compared to Android's (the CPU usage is 30% only!) but is workable for now.

By the way, It will take a long time to change sessionPresent when your captureSession is already running. For my situation, I need to stop it temporarily and start it latter after making changes.

from apprtc-ios.

allenzyq avatar allenzyq commented on September 27, 2024

hi all.
how can you fixup the video card problem?

from apprtc-ios.

hengtelin avatar hengtelin commented on September 27, 2024

is this problem fixed in the newest version? Or do we still need to make changes manually?

from apprtc-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.