GVKun编程网logo

objective-c – 如何在swift中创建VTCompressionSession?(swift创建对象)

5

对于objective-c–如何在swift中创建VTCompressionSession?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍swift创建对象,并为您提供关于com.intell

对于objective-c – 如何在swift中创建VTCompressionSession?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍swift创建对象,并为您提供关于com.intellij.psi.PsiClassObjectAccessExpression的实例源码、Error: [$compile:nonassign] Expression used with directive ''uibTab'' is non-assignable、io.netty.handler.codec.compression.CompressionException的实例源码、ios – FBSession.openActiveSessionWithReadPermissions未调用completionHandler的有用信息。

本文目录一览:

objective-c – 如何在swift中创建VTCompressionSession?(swift创建对象)

objective-c – 如何在swift中创建VTCompressionSession?(swift创建对象)

我一直在寻找如何创建VTCompressionSession(在 swift中)的高低,如 2014 WWDC Video – ‘Direct Access to Video Encoding and Decoding’中简要提到的那样.

以下代码适用于Objective-C:

#import <Foundation/Foundation.h>
#import <VideoToolBox/VideoToolBox.h>

int main(int argc,const char * argv[]) {
    @autoreleasepool {
        VTCompressionSessionRef session;
        VTCompressionSessionCreate(NULL,500,kCMVideoCodecType_H264,NULL,&session);

        NSLog(@"created VTCompressionSession");
    }
    return 0;
}

但无论我尝试过什么,我都找不到将VTCompressionSessionCreate导入swift的方法.

import Foundation
import VideoToolBox

VideoToolBox.VTCompressionSessionCreate()

println("created VTCompressionSession")

例如,此代码中断:模块“VideoToolBox”没有名为“VTCompressionSessionCreate”的成员.
只需调用VTCompressionSessionCreate就会创建错误消息Use of unresolved identifier’VTCompressionSessionCreate’.

看起来它没有暴露在swift中,因为我可以调用像VTCompressionSessionEncodeFrame这样的方法.我错过了一些明显的东西吗

解决方法

我的解决方法是编写一个objective-c函数并通过bridging-header将其公开给swift:

Compression.h

#import <VideoToolBox/VideoToolBox.h>
VTCompressionSessionRef CreateCompressionSession();

Compression.m

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <VideoToolBox/VideoToolBox.h>

VTCompressionSessionRef CreateCompressionSession(){
    NSLog(@"CreateCompressionSession");
    VTCompressionSessionRef session;
    VTCompressionSessionCreate(NULL,&session);
    return session;
}

流桥接-Header.h

#import "CompressionSession.h"

现在,您可以在swift中运行以下代码:

import Cocoa
import Foundation
import VideoToolBox

let session = CreateCompressionSession()

com.intellij.psi.PsiClassObjectAccessExpression的实例源码

com.intellij.psi.PsiClassObjectAccessExpression的实例源码

项目:errai-intellij-idea-plugin    文件:Util.java   
public static String getAttributeValue(PsiAnnotation annotation,String attributeName,DefaultPolicy policy) {
  final PsiAnnotationMemberValue value = getAnnotationMemberValue(annotation,attributeName);
  if (value != null) {
    if (value instanceof PsiClassObjectAccessExpression) {
      final PsiType type = ((PsiClassObjectAccessExpression) value).getType();
      if (type == null) {
        return null;
      }
      return type.getCanonicalText();
    }
    else {
      final String text = value.getText();
      return text.substring(1,text.length() - 1);
    }
  }

  if (policy == DefaultPolicy.OWNER_IDENTIFIER_NAME) {
    return PsiUtil.getName(getImmediateOwnerElement(annotation));
  }
  else {
    return null;
  }
}
项目:consulo-java    文件:PsiMemberParameterizedLocation.java   
public static Location getParameterizedLocation(PsiClass psiClass,String paramSetName,String parameterizedClassName)
{
    final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(psiClass,Collections.singleton(JUnitUtil.RUN_WITH));
    if(annotation != null)
    {
        final PsiAnnotationMemberValue attributeValue = annotation.findAttributeValue("value");
        if(attributeValue instanceof PsiClassObjectAccessExpression)
        {
            final PsiTypeElement operand = ((PsiClassObjectAccessExpression) attributeValue).getoperand();
            if(InheritanceUtil.isInheritor(operand.getType(),parameterizedClassName))
            {
                return new PsiMemberParameterizedLocation(psiClass.getProject(),psiClass,null,paramSetName);
            }
        }
    }
    return null;
}
项目:intellij-mockito-postfix-plugin    文件:MockTemplate.java   
@Nullable
@Override
public String getTemplateString(PsiElement psiElement) {
    String clazz;
    if (psiElement instanceof PsiReference) {
        // foo.mock
        PsiReference psiReference = (PsiReference) psiElement;
        PsiLocalVariable psiLocalVariable = (PsiLocalVariable) psiReference.resolve();
        if (psiLocalVariable == null) {
            return psiElement.getText();
        }
        PsiType psiType = psiLocalVariable.getType();
        clazz = psiType.getPresentableText() + ".class";
    } else if (psiElement instanceof PsiClassObjectAccessExpression) {
        // String.class.mock
        PsiClassObjectAccessExpression psiClassObjectAccessExpression = (PsiClassObjectAccessExpression) psiElement;
        String classtext = psiClassObjectAccessExpression.getText();
        if (classtext == null) {
            return psiElement.getText();
        }
        clazz = classtext;
    } else {
        return psiElement.getText();
    }

    return "org.mockito.Mockito.mock(" + clazz + ")$END$";
}
项目:consulo-java    文件:ExcludeFromCompletionLookupActionProvider.java   
@Override
public void fillActions(LookupElement element,Lookup lookup,Consumer<LookupElementAction> consumer)
{
    Object o = element.getobject();
    if(o instanceof PsiClassObjectAccessExpression)
    {
        o = PsiUtil.resolveClassInType(((PsiClassObjectAccessExpression) o).getoperand().getType());
    }

    if(o instanceof PsiClass)
    {
        PsiClass clazz = (PsiClass) o;
        addExcludes(consumer,clazz,clazz.getQualifiedname());
    }
    else if(o instanceof PsiMethod)
    {
        final PsiMethod method = (PsiMethod) o;
        if(method.hasModifierProperty(PsiModifier.STATIC))
        {
            addExcludes(consumer,method,PsiUtil.getMemberQualifiedname(method));
        }
    }
    else if(o instanceof PsiField)
    {
        final PsiField field = (PsiField) o;
        if(field.hasModifierProperty(PsiModifier.STATIC))
        {
            addExcludes(consumer,field,PsiUtil.getMemberQualifiedname(field));
        }
    }
}
项目:consulo-java    文件:ConstantExpressionPredicate.java   
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsipolyadicExpression)) {
    return false;
  }
  if (element instanceof PsiLiteralExpression || element instanceof PsiClassObjectAccessExpression) {
    return false;
  }
  final PsipolyadicExpression expression = (PsipolyadicExpression)element;
  final PsiType expressionType = expression.getType();
  if (expressionType == null || expressionType.equalsToText("java.lang.String")) {
    // intention disabled for string concatenations because of performance issues on
    // relatively common large string expressions.
    return false;
  }
  final PsiExpression[] operands = expression.getoperands();
  for (PsiExpression operand : operands) {
    if (operand == null) {
      return false;
    }
    final PsiType type = operand.getType();
    if (type == null || type.equalsToText("java.lang.String")) {
      return false;
    }
  }
  if (!PsiUtil.isConstantExpression(expression)) {
    return false;
  }
  try {
    final Object value = ExpressionUtils.computeConstantExpression(expression,true);
    if (value == null) {
      return false;
    }
  }
  catch (ConstantEvaluationOverflowException ignore) {
    return false;
  }
  final PsiElement parent = element.getParent();
  return !(parent instanceof PsiExpression) || !PsiUtil.isConstantExpression((PsiExpression)parent);
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassstructureDetector.java   
@Override
public void visitClassObjectAccessExpression(PsiClassObjectAccessExpression expression) {
    mVisitor.report("PsiClassObjectAccessExpression",expression.getText(),expression);
    super.visitExpression(expression);
}

Error: [$compile:nonassign] Expression used with directive ''uibTab'' is non-assignable

Error: [$compile:nonassign] Expression used with directive ''uibTab'' is non-assignable

I''ve a simple scenario. Two tabs, tab 1 & 2. Need to be able to select Tab 1 via link.

Html:

<p>
  <a href="#" ng-click="selectTab1()">
    <span></span> Select TAB 1
  </a>
</p>
<uib-tabset>
  <uib-tab heading="Tab 1" active="activeTab==true" ng-click="clickTab1()">
    Content 1
  </uib-tab>
  <uib-tab heading="Tab 2 (default)" active="activeTab==false" ng-click="clickTab2()">
    Content 2
  </uib-tab>
</uib-tabset>

 Controller code here:

  $scope.activeTab = false;

  $scope.selectTab1 = function() {
    $scope.activeTab = true;
  }
  $scope.clickTab1 = function() {
    $scope.activeTab = true;
  }
  $scope.clickTab2 = function() {
    $scope.activeTab = false;
  }

Plunker is here: http://plnkr.co/edit/5yBHmXZBHyWYZEtmshad?p=info

When clicking in Tab 1 or 2, I''m getting the following error:

Error: [$compile:nonassign] Expression ''activeTab==true'' used with directive ''uibTab'' is non-assignable!

I could change this expression ''activeTab==true'' to a shorter way like ''activeTab'' but It doesn''t seems to be working.

2 Answers

1、It is better to update a scope variable and bind it to active attribute of your tabs:

$scope.activeTab = [];

$scope.selectTab1 = function(index) {
    $scope.activeTab[index] = true;
  };

$scope.clickTab = function(index) {
  $scope.activeTab[index] = true;
};

In your view:

<uib-tab heading="Tab 1" active="activeTab[0]" ng-click="clickTab(0)">
  Content 1
</uib-tab>
<uib-tab heading="Tab 2 (default)" active="activeTab[1]" ng-click="clickTab(1)">
  Content 2
</uib-tab>

I have updated the plunkr

This also makes the implementation to be more re-usable than before (For instance, it can be easily used inside a ng-repeat if the need arises).

Reference: GitHub Issue

2、For the latest version of uib (2.4.0) it should be like this:

In controller:

$scope.activeTab = 1;

In view:

<uib-tabset active="activeTab">
    <uib-tab index="0" heading="Tab 1">
        Content 1
    </uib-tab>
    <uib-tab index="1" heading="Tab 2">
        Content 2
    </uib-tab>
</uib-tabset>

io.netty.handler.codec.compression.CompressionException的实例源码

io.netty.handler.codec.compression.CompressionException的实例源码

项目:netty4study    文件:SpdyHeaderBlockJZlibEncoder.java   
private void encode(ByteBuf compressed) {
    try {
        byte[] out = new byte[(int) Math.ceil(z.next_in.length * 1.001) + 12];
        z.next_out = out;
        z.next_out_index = 0;
        z.avail_out = out.length;

        int resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException("compression failure: " + resultCode);
        }

        if (z.next_out_index != 0) {
            compressed.writeBytes(out,z.next_out_index);
        }
    } finally {
        // Deference the external references explicitly to tell the VM that
        // the allocated byte arrays are temporary so that the call stack
        // can be utilized.
        // I'm not sure if the modern VMs do this optimization though.
        z.next_in = null;
        z.next_out = null;
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:SpdyHeaderBlockJZlibEncoder.java   
private void encode(ByteBuf compressed) {
    try {
        byte[] out = new byte[(int) Math.ceil(z.next_in.length * 1.001) + 12];
        z.next_out = out;
        z.next_out_index = 0;
        z.avail_out = out.length;

        int resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException("compression failure: " + resultCode);
        }

        if (z.next_out_index != 0) {
            compressed.writeBytes(out,z.next_out_index);
        }
    } finally {
        // Deference the external references explicitly to tell the VM that
        // the allocated byte arrays are temporary so that the call stack
        // can be utilized.
        // I'm not sure if the modern VMs do this optimization though.
        z.next_in = null;
        z.next_out = null;
    }
}
项目:netty4.0.27Learn    文件:SpdyHeaderBlockJZlibEncoder.java   
SpdyHeaderBlockJZlibEncoder(
        SpdyVersion version,int compressionLevel,int windowBits,int memLevel) {
    super(version);
    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel + " (expected: 0-9)");
    }
    if (windowBits < 9 || windowBits > 15) {
        throw new IllegalArgumentException(
                "windowBits: " + windowBits + " (expected: 9-15)");
    }
    if (memLevel < 1 || memLevel > 9) {
        throw new IllegalArgumentException(
                "memLevel: " + memLevel + " (expected: 1-9)");
    }

    int resultCode = z.deflateInit(
            compressionLevel,windowBits,memLevel,JZlib.W_ZLIB);
    if (resultCode != JZlib.Z_OK) {
        throw new CompressionException(
                "Failed to initialize an SPDY header block deflater: " + resultCode);
    } else {
        resultCode = z.deflateSetDictionary(SPDY_DICT,SPDY_DICT.length);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException(
                    "Failed to set the SPDY dictionary: " + resultCode);
        }
    }
}
项目:netty4study    文件:SpdyHeaderBlockJZlibEncoder.java   
public SpdyHeaderBlockJZlibEncoder(
        SpdyVersion version,SPDY_DICT.length);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException(
                    "Failed to set the SPDY dictionary: " + resultCode);
        }
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:SpdyHeaderBlockJZlibEncoder.java   
public SpdyHeaderBlockJZlibEncoder(
        SpdyVersion version,SPDY_DICT.length);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException(
                    "Failed to set the SPDY dictionary: " + resultCode);
        }
    }
}
项目:netty4.0.27Learn    文件:SpdyHeaderBlockJZlibEncoder.java   
private ByteBuf encode(ByteBufAllocator alloc) {
    boolean release = true;
    ByteBuf out = null;
    try {
        int oldNextinindex = z.next_in_index;
        int oldNextOutIndex = z.next_out_index;

        int maxOutputLength = (int) Math.ceil(z.next_in.length * 1.001) + 12;
        out = alloc.heapBuffer(maxOutputLength);
        z.next_out = out.array();
        z.next_out_index = out.arrayOffset() + out.writerIndex();
        z.avail_out = maxOutputLength;

        int resultCode;
        try {
            resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
        } finally {
            out.skipBytes(z.next_in_index - oldNextinindex);
        }
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException("compression failure: " + resultCode);
        }

        int outputLength = z.next_out_index - oldNextOutIndex;
        if (outputLength > 0) {
            out.writerIndex(out.writerIndex() + outputLength);
        }
        release = false;
        return out;
    } finally {
        // Deference the external references explicitly to tell the VM that
        // the allocated byte arrays are temporary so that the call stack
        // can be utilized.
        // I'm not sure if the modern VMs do this optimization though.
        z.next_in = null;
        z.next_out = null;
        if (release && out != null) {
            out.release();
        }
    }
}

ios – FBSession.openActiveSessionWithReadPermissions未调用completionHandler

ios – FBSession.openActiveSessionWithReadPermissions未调用completionHandler

我正在使用Facebook SDK实现OAuth登录,但是FBSession.openActiveSessionWithReadPermissions:allowLoginUI:completionHandler方法没有调用completionHandler,也没有返回“true”,这表示缓存的令牌.除此之外,其他一切似乎都很好.这段代码出了什么问题?

var completionHandler: FBSessionStateHandler = {

        session,status,error in

        NSLog("token not cached");

        if error {

            // Login Failed for some reason,so we notify the delegate.
            self.delegate.didFailOpenningSession?(self,withError: ErrorUtility.error(
                code: .FailedOpenningSession,withFacebookError: error
            ));

            // Don't proceed on errors
            return;
        }

        // Session is Now open,we should notify the delegate
        self.delegate.didOpenSession?(self);
    };

    NSLog("here");

    // Open the session,prompting the user if necessary. This might send the application to the background
    if FBSession.openActiveSessionWithReadPermissions(["public_profile"],allowLoginUI: true,completionHandler: completionHandler) {

        NSLog("Token cached");

        // If we end up here,the session token must exist,so we Now have an open session
        self.delegate.didOpenSession?(self);
    }

编辑:我忘了提到NSLog记录“这里”,但不是“令牌缓存”或“令牌没有缓存”

编辑:现在事情有点奇怪了.当我的应用程序启动时,我会显示一个带有Facebook登录按钮的屏幕.当用户按下按钮时,上面的代码被触发.在我授权应用程序之后,应用程序返回到同一个屏幕(它不应该,但是在调用完成处理程序之前我不能以任何其他方式执行).然后我再次尝试按下按钮,现在我确实得到了日志.

这就是我得到的:

here
    token not cached
    here

第一行是从第一次按下按钮,另外两行是在我第二次按下时出现的.现在有什么奇怪的呢?不应该“令牌没有缓存”和“这里”被逆转???它是从最后一次通话中调用competionHandler还是其他什么东西?

没关系,这很多都是固定的.

编辑:另一件事.如果我多次按下按钮,我总是得到“令牌未缓存”.我认为它应该是缓存

解决方法

它已经解决了.我错过了方法AppDelegate.application:handleOpenURL – >布尔

今天关于objective-c – 如何在swift中创建VTCompressionSession?swift创建对象的讲解已经结束,谢谢您的阅读,如果想了解更多关于com.intellij.psi.PsiClassObjectAccessExpression的实例源码、Error: [$compile:nonassign] Expression used with directive ''uibTab'' is non-assignable、io.netty.handler.codec.compression.CompressionException的实例源码、ios – FBSession.openActiveSessionWithReadPermissions未调用completionHandler的相关知识,请在本站搜索。

本文标签: