Jump to content

4 posts in this topic

Recommended Posts

Posted

YO IOSGOds,

anyone know an working (ios 8.1+) lib for rtsp streaming?

 

(Move this thread if its in wrong section :S)

What is "rtsp"?

Posted

My current source..:

 

#import "ViewController.h"

#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
#include "libavutil/pixdesc.h"


@interface ViewController ()
{
    AVFormatContext *pFormatCtx;
    AVCodecContext *pAudioCodeCtx;
    
    int   audioStream;
    BOOL  isStop;
    
}

- (void)stopPlay;
- (void)startPlay;

@end

@implementation ViewController

@synthesize Label;

//rtp://@239.35.10.1:10000


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.Label.text = @"Nothing....";
    [self.MyButton setTitle:@"Start" forState:UIControlStateNormal];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)Button:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    
    if([btn.currentTitle isEqualToString:@"Stop"])
    {
        self.stopPlay;
        
        [btn setTitle:@"Play" forState:UIControlStateNormal];
    }else{
        self.startPlay;
        [btn setTitle:@"Stop" forState:UIControlStateNormal];
    }
    
}

- (void)stopPlay
{
    isStop = YES;
    avformat_network_deinit();
    self.Label.text = @"stopppped";
}

- (void)startPlay
{
    isStop = NO;
    self.Label.text = @"starting";
    
    avcodec_register_all();
    av_register_all();
    avformat_network_init();
    
    NSString *const kTestPath = @"rtp://@239.35.10.4:10000";
    NSString *pAudioInPath;
    
    AVCodec *pAudioCodec;
   // AVFrame *pFrame;
    
    pAudioInPath = kTestPath;
    
     //pFrame = avcodec_alloc_frame();
    
    //Maybe simple NULL?
    if (avformat_open_input(&pFormatCtx, [pAudioInPath cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL) != 0)
    {
        NSLog(@"Could not open connection");
        self.Label.text = @"Could not open connection";
        return;
    }
    
     pAudioInPath = nil;
    
    if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
    {
        NSLog(@"Could not find streaming information");
        self.Label.text = @"Could not find streaming information";
        return;
    }
    avformat_close_input(&pFormatCtx);
    
     av_dump_format(pFormatCtx, 0, [pAudioInPath UTF8String], 0);
    
    // Find the first audio stream
    if ((audioStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, &pAudioCodec, 0)) < 0)
    {
        NSLog(@"Could not find a audio streaming information");
        self.Label.text = @"Could not find a audio streaming information";
        return;
    } else {
        // Succeed to get streaming information
        NSLog(@"== Audio pCodec Information");
        NSLog(@"name = %s",pAudioCodec->name);
        NSLog(@"sample_fmts = %d",*(pAudioCodec->sample_fmts));
        
        if (pAudioCodec->profiles)
        {
            NSLog(@"Profile names = %@", pAudioCodec->profiles);
            
        } else {
            NSLog(@"Profile is Null");
            
        }
        
        // Get a pointer to the codec context for the video stream
        pAudioCodeCtx = pFormatCtx->streams[audioStream]->codec;
        
        // Find out the decoder
        pAudioCodec = avcodec_find_decoder(pAudioCodeCtx->codec_id);
        
        // Open codec
        if (avcodec_open2(pAudioCodeCtx, pAudioCodec, NULL) < 0)
        {
            //stop
            self.Label.text = @"stoppped";
            return;
        }
    }
    
    isStop = NO;
    
}

@end

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines