#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    11
    Rep Power
    0

    How do i make that the function will show me all the types of codecs there is ?


    In C i have:

    Code:
    const char* Encoder_av_get_media_type_string(enum AVMediaType media_type)
    {
    	switch (media_type) {
            case AVMEDIA_TYPE_VIDEO:      return "video";
            case AVMEDIA_TYPE_AUDIO:      return "audio";
            case AVMEDIA_TYPE_DATA:       return "data";
            case AVMEDIA_TYPE_SUBTITLE:   return "subtitle";
            case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
            default:                      return NULL;
            }
    }
    Then in the header file which connect between the C and the CLI i have:
    
    const char* Encoder_av_get_media_type_string(enum AVMediaType media_type);
    Then in the CLI i have:

    Code:
    property List<String^> ^GetCodec
    {
    
    	List<String^>^ get()
        {
            List<String^> ^l = gcnew List<String^>;
            String ^s;
    		s = gcnew String(Encoder_av_get_media_type_string(avm));
            l->Add(s);
            
    
            return l;
        }
    }
    Then in CSHARP:
    
    List<string> ss = new List<string>();
                for (int i = 0; i < f.GetCodec.Count; i++)
                {
                    ss.Add(f.GetCodec[i]);
                }
    But in the end also in CLI and also in CSHARP i'm getting one type i see in CSHARP that the variable ss contain only "video" i want it to contain all the other 6 types too.

    How can i do it ?



    I changed the type of the function in the cli to List<String^> type:

    Code:
    List<String^> ^GetCodecsTypes()
    {
    	    List<String^> ^l = gcnew List<String^>;
            String ^s;
    		s = gcnew String(Encoder_av_get_media_type_string();
    		
            return l;
        
    }
    I'm not sure what i should put in the () of the: Encoder_GetCurrentCodecName()

    It should get: AVMediaType media_type

    Then in Csharp this is my button1 click event code:

    Code:
    private void button1_Click(object sender, EventArgs e)
            {
                f = new FFMPEGWrapper();
                List<FFMPEGWrapper> l = f.GetCodecs();
                var video_codecs = l.Where(w => w.CodecType == 0);
                var audio_codecs = l.Where(w => w.CodecType == 1);
                List<string> names =
                    new[] { "***Video Codecs***" }
                    .Concat(video_codecs.Select(w => w.CodecName))
                    .Concat(new[] { "***Audio Codecs***" })
                    .Concat(audio_codecs.Select(w => w.CodecName))
                    .ToList();
    So i want to use it like: List<String> s = f.GetCodecsTypes();

    But i dont know how to make it right in the CLI file and in the C file.

    In the C file i didn;t change anything it's still as it was before:


    Code:
    const char* Encoder_av_get_media_type_string(enum AVMediaType media_type)
    {
    	switch (media_type) {
            case AVMEDIA_TYPE_VIDEO:      return "video";
            case AVMEDIA_TYPE_AUDIO:      return "audio";
            case AVMEDIA_TYPE_DATA:       return "data";
            case AVMEDIA_TYPE_SUBTITLE:   return "subtitle";
            case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
            default:                      return NULL;
            }
    }
    In the end in Csharp i want that the variable s will contain all the types names.

    OPTIONAL:
    And maybe if it's possible i wanted to do it in the CLI or even in the C file that it will return all the types names without doing it manualy like it is now in C to return each type but to return a List of all the types to csharp.


    But first i don't know yet how to send it in the first time all the types names to Csharp.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    Well, first of all, you can't return anything but really simple types to C# from a C function. Why are you even trying? Pick a language. Or encapsulate your C functionality in a small program that outputs a list of codecs (one per line) to stdout and then redirect that to your C# program.

    Now, in C++ you can do a lot more with the CLR directly, but it's not really supported any more. C++ programmers pretty much hate what Microsoft did in the way of language extensions to support .NET and virtually no one uses it.

    If you are new to programming and you are going to write .NET Windows applications, you might as well learn to live with C# or give up on .NET.
    I no longer wish to be associated with this site.

IMN logo majestic logo threadwatch logo seochat tools logo